Skip to content

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

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

Closed
spring-projects-issues opened this issue Oct 15, 2018 · 3 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: task A general task
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

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-projects-issues
Copy link
Collaborator Author

Bob Tiernay commented

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

@spring-projects-issues
Copy link
Collaborator Author

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-projects-issues
Copy link
Collaborator Author

Bob Tiernay commented

Thanks for the quick clarification!

@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches in: core Issues in core modules (aop, beans, core, context, expression) type: task A general task labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 5.1.2 milestone Jan 11, 2019
This was referenced Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: backported An issue that has been backported to maintenance branches type: task A general task
Projects
None yet
Development

No branches or pull requests

2 participants