Announcement Announcement Module

JavaConfig forum decommissioned in favor of Core Container

As described at

key features of the Spring JavaConfig project have been migrated into the core Spring Framework as of version 3.0.

Please see the Spring 3.0 documentation on @Configuration and @Bean support:

For any questions related to @Configuration classes and @Bean methods in Spring 3.0, please post in the dedicated 'Core Container' forum at
See more
See less
Naming a bean using @Bean? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Naming a bean using @Bean?

    It looks like it should be fairly easy to add the ability to name a bean using the @Bean annotation. Is there a reason this does not seem to have been done and would not be a good idea? (if there is already a way to name beans then my apologies and I would appreciate a docs link)

    I certainly understand using the BeanNamingStrategy as a way to generally override default naming but it seems like a weakness to not be able to name beans when defining them.

  • #2
    You're quite right to expect this, and it's a gap in functionality right now. I'd appreciate it if you'd add a JIRA issue to this effect.

    In the meantime, you can use the @Bean(aliases="customName") as a workaround. It will mean that the bean is registered under both names (from the method and from the alias) which may or may not work for you.