Take the following two ways of declaring a bean definition manually.
@Configuration
class MyConfiguration {
private final MyRepository repository;
MyConfiguration(MyRepository repository) {
this.repository = repository;
}
@Bean MyService myService() {
return new MyService(repository);
}
}
In this case, the implicit dependency from MyService to MyRepository is not taken into account on the BeanDefinition level which has consequences on the destruction order on container shutdown. The repository might already shut down so that destruction callbacks on MyService will not be able to use the repository anmore.
@Configuration
class MyConfiguration {
@Bean MyService myService(MyRepository repository) {
return new MyService(repository);
}
}
In this case the dependency is properly transferred into the `BeanDefinition` arrangement and `MyService` is destructed before `MyRepository`.
Take the following two ways of declaring a bean definition manually.
In this case, the implicit dependency from
MyServicetoMyRepositoryis not taken into account on theBeanDefinitionlevel which has consequences on the destruction order on container shutdown. The repository might already shut down so that destruction callbacks onMyServicewill not be able to use the repository anmore.