Skip to content

Java based config should support class-only component declarations through @Import [SPR-11740] #16362

Closed
@spring-projects-issues

Description

@spring-projects-issues

Marty Pitt opened SPR-11740 and commented

Currently, when declaring my beans via Java config, I'm provided with two options:

  • Implicitly, without construction responsibility -- Using a @Component annotation, and let Spring discover the bean.
  • Explicitly, with construction responsibility -- Using a @Bean annotation within a @Configuration class.

There is a valid use case where I would like to explicitly declare a set of beans, but leave Spring responsible for their construction.

This is analogous to the classic <bean class=""> xml approach.

A possible syntax for this would be:

@Configuration 
public class MyAppConfig {

    // Explictly provide the class, not the instance to Spring
    @Bean
    public MyFunkySpringBean funkyBean; // No instance -- it's up to Spring to build
}

Reference URL: http://stackoverflow.com/questions/23313262/spring-java-config-specify-class-only

Issue Links:

Referenced from: commits f0ac278, a15dc08

1 votes, 9 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