Skip to content

Introduce support for non-@Primary fallback beans #26241

Closed
@raphw

Description

@raphw

Sometimes, one wants to be able to register a bean of a given type without breaking existing code, especially in multi-module projects. Assuming that a bean is already available:

@Bean
public SomeType someTypeBean() {
  return new SomeType();
}

and used as in:

@Bean
public SomeOtherType someOtherTypeBean(SomeType val) {
  return new SomeOtherType(val);
}

I would like to being able to register a bean:

@Bean
@Secondary // mirrored behavior of @Primary
public SomeType someNewTypeBean() {
  return new SomeType();
}

without disturbing existing code. If the someTypeBean is missing, it should fallback to someNewTypeBean, this would also allow for much smoother migrations in the case of multiple profiles.

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions