Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify if @DependsOn influences bean destroy lifecycle ordering [SPR-17384] #21917

Closed
spring-issuemaster opened this issue Oct 15, 2018 · 3 comments

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Oct 15, 2018

Bob Tiernay opened SPR-17384 and commented

Currently it is unclear from the documentation if having a @DependsOn relationship between two beans implies that the dependant bean will be destroyed after the dependency: 

https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#sect5

??If you want to influence the startup creation order of certain beans, consider declaring some of them as @Lazy(for creation on first access instead of on startup) or as @DependsOn certain other beans (making sure that specific other beans are created before the current bean, beyond what the latter’s direct dependencies imply).??

https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/context/annotation/DependsOn.html

??Beans on which the current bean depends. Any beans specified are guaranteed to be created by the container before this bean. Used infrequently in cases where a bean does not explicitly depend on another through properties or constructor arguments, but rather depends on the side effects of another bean's initialization.??

However, the semantics of destroy are clear in the XML case:

https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#beans-factory-dependson

??The depends-on attribute in the bean definition can specify both an initialization-time dependency and, in the case of singleton beans only, a corresponding destroy-time dependency. Dependent beans that define a depends-on relationship with a given bean are destroyed first, prior to the given bean itself being destroyed. Thus, depends-on can also control shutdown order.??

 


Referenced from: commits c73b98c, 00b7782, a3bdeb2

Backported to: 5.0.11, 4.3.21

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 15, 2018

Bob Tiernay commented

Before moving forward, can you please comment on what the documented change should be?

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 15, 2018

Juergen Hoeller commented

Any kind of depends-on declaration consistently affects initialization as well as shutdown order, so the XML docs are right and the @DependsOn docs should simply also say so.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 15, 2018

Bob Tiernay commented

Thanks for the quick clarification!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.