Skip to content

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

@odrotbohm

Description

@odrotbohm

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`.

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)status: backportedAn issue that has been backported to maintenance branchestype: enhancementA general enhancement

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions