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

Register bean definition dependencies when used via configuration class injected fields #26167

Closed
odrotbohm opened this issue Nov 27, 2020 · 0 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: enhancement A general enhancement
Milestone

Comments

@odrotbohm
Copy link
Member

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`.
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Nov 27, 2020
@jhoeller jhoeller self-assigned this Nov 27, 2020
@jhoeller jhoeller added in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Nov 27, 2020
@jhoeller jhoeller added this to the 5.3.2 milestone Nov 27, 2020
@jhoeller jhoeller changed the title Bean definition dependencies lost when used via configuration class injected fields Register bean definition dependencies when used via configuration class injected fields Nov 27, 2020
@jhoeller jhoeller added the for: backport-to-5.2.x Marks an issue as a candidate for backport to 5.2.x label Nov 27, 2020
@spring-projects-issues spring-projects-issues added status: backported An issue that has been backported to maintenance branches and removed for: backport-to-5.2.x Marks an issue as a candidate for backport to 5.2.x labels Nov 27, 2020
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: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants