Skip to content

Add a functional way to register a bean [SPR-14832] #19398

Closed
@spring-projects-issues

Description

@spring-projects-issues

Hans Desmet opened SPR-14832 and commented

Add a registerBean method to ApplicationContext which accepts a lambda with which you register as bean.

The following code uses this method to register a bean of a class A and to register a
bean of class B which has a dependency on class A

@Configuration
public class MyConfiguration
  private final ApplicationContext context;
  public MyConfiguration(ApplicationContext context) {
    this.context = context;
    context.registerBean(AClass.class -> new AClass());
    context.registerBean(BClass.class -> new BClass(context.getBean(AClass.class));
  }

Affects: 5.0 M2

Issue Links:

1 votes, 8 watchers

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