|
|
<table>
|
|
|
<thead>
|
|
|
<tr>
|
|
|
<th width="200px"><h6>[:rewind: Exo Précédent](/Exo05-Init-et-Destroy/1%5D-Code-Java)</h6></th>
|
|
|
<th colspan="4" width="600px"><h1 align="center">06 - Spring - Scope et Context</h1></th>
|
|
|
<th width="200px"><h6 align="right">[Exo Suivant :fast_forward:](/Exo07-Declaration-Bean/1%5D-Code-Java)</h6></th>
|
|
|
</tr>
|
|
|
</thead>
|
|
|
|
|
|
<tbody>
|
|
|
<tr>
|
|
|
<td> </td>
|
|
|
<td align="center">[:one:](/Exo06-Scope-et-context/1%5D-Code-Java)<br/>Code Java</td>
|
|
|
<td align="center">[:two:](/Exo06-Scope-et-context/2%5D-XML)<br/>XML</td>
|
|
|
<td align="center">[:three:](/Exo06-Scope-et-context/3%5D-Configuration)<br/>Configuration</td>
|
|
|
<td align="center">:white_check_mark:<br/>Spring Boot</td>
|
|
|
<td> </td>
|
|
|
</tr>
|
|
|
</tbody>
|
|
|
|
|
|
<tfoot>
|
|
|
<tr align="right">
|
|
|
<td colspan="6">
|
|
|
<h6>:copyright: 2019 - <a href="mailto:admin@ferretrenaud.fr">FERRET Renaud</a></h6>
|
|
|
</td>
|
|
|
</tr>
|
|
|
</tfoot>
|
|
|
</table>
|
|
|
|
|
|
***
|
|
|
|
|
|
# Modification de votre classe de lancement
|
|
|
L'utilisation de name space n'a de sens que dans le cas des fichiers XML, il n'y a donc rien de particulier dans les classes de configuration (et Spring Boot en est une).
|
|
|
|
|
|
Ajoutez l'annotation [@Scope](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/beans/factory/config/Scope.html) à un de vos bean client et adresse.
|
|
|
|
|
|
Relancez votre code et regardez ce qui se passe selon que vous indiquez `ConfigurableBeanFactory.SCOPE_SINGLETON` ou `ConfigurableBeanFactory.SCOPE_PROTOTYPE`.
|
|
|
```java
|
|
|
...
|
|
|
@Bean(initMethod = "initialiser", destroyMethod = "detruire")
|
|
|
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
|
|
public Client client1() {
|
|
|
...
|
|
|
}
|
|
|
...
|
|
|
```
|
|
|
# Bonus
|
|
|
Comment modifier le code de sa méthode main pour prouver que le `@Scope` est bien respecté ?
|
|
|
|
|
|
***
|
|
|
|
|
|
<table>
|
|
|
<thead>
|
|
|
<tr>
|
|
|
<th width="200px"><h6>[:rewind: Exo Précédent](/Exo05-Init-et-Destroy/1%5D-Code-Java)</h6></th>
|
|
|
<th colspan="4" width="600px"><h1 align="center">06 - Spring - Scope et Context</h1></th>
|
|
|
<th width="200px"><h6 align="right">[Exo Suivant :fast_forward:](/Exo07-Declaration-Bean/1%5D-Code-Java)</h6></th>
|
|
|
</tr>
|
|
|
</thead>
|
|
|
|
|
|
<tbody>
|
|
|
<tr>
|
|
|
<td> </td>
|
|
|
<td align="center">[:one:](/Exo06-Scope-et-context/1%5D-Code-Java)<br/>Code Java</td>
|
|
|
<td align="center">[:two:](/Exo06-Scope-et-context/2%5D-XML)<br/>XML</td>
|
|
|
<td align="center">[:three:](/Exo06-Scope-et-context/3%5D-Configuration)<br/>Configuration</td>
|
|
|
<td align="center">:white_check_mark:<br/>Spring Boot</td>
|
|
|
<td> </td>
|
|
|
</tr>
|
|
|
</tbody>
|
|
|
|
|
|
<tfoot>
|
|
|
<tr align="right">
|
|
|
<td colspan="6">
|
|
|
<h6>:copyright: 2019 - <a href="mailto:admin@ferretrenaud.fr">FERRET Renaud</a></h6>
|
|
|
</td>
|
|
|
</tr>
|
|
|
</tfoot>
|
|
|
</table> |