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

[Enhancement] @Bean can only inject one dependency,can I inject many dependencies in one method? #14978

Closed
Paleozoic opened this issue Oct 27, 2018 · 1 comment

Comments

@Paleozoic
Copy link

@Paleozoic Paleozoic commented Oct 27, 2018

When inject two beans,such as the following code:

@Bean("bean1")
public Bean buildBean1(){
    Bean bean = new Bean();
    return bean ;
}
@Bean("bean2")
public Bean buildBean2(){
    Bean bean = new Bean();
    return bean ;
}

can I just write the code? such as:

@Beans
public Map<String,Bean> buildBeans(){
    Map<String,Bean> beans = new HashMap<>();
    beans.put("bean1",new Bean());
    beans.put("bean2",new Bean());
    return beans ;
}

sometimes we can not confirm how many beans to inject,we have to write complex BeanDefinition and then registerBeanDefinition.
if we have @Beans,everything is easy~

@Paleozoic Paleozoic changed the title [Enhancement] @Bean can only inject one dependency,can I inject many dependencies one time? [Enhancement] @Bean can only inject one dependency,can I inject many dependencies in one time? Oct 27, 2018
@Paleozoic Paleozoic changed the title [Enhancement] @Bean can only inject one dependency,can I inject many dependencies in one time? [Enhancement] @Bean can only inject one dependency,can I inject many dependencies in one method? Oct 27, 2018
@philwebb

This comment has been minimized.

Copy link
Member

@philwebb philwebb commented Oct 27, 2018

The @Bean annotation and @Configuration processing code is part of Spring Framework so you'll need to raise a JIRA for this.

I'm personally not convinced this is a good idea given the limited number of times users will need to create multiple beans in one go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.