Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring bean name and annotations

 
Joe Chambers
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We use a vendor package that accesses spring beans via the bean "name" as in <bean name="/proxy">...</bean>. As we upgrade to spring 3.0 we are trying to use annotation configuration instead of xml.

Since the bean name can include values that are not allowed in bean id's, is there a method for doing this in annotations i.e. Component, Repository...?

Thanks
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Chambers wrote:We use a vendor package that accesses spring beans via the bean "name" as in <bean name="/proxy">...</bean>. As we upgrade to spring 3.0 we are trying to use annotation configuration instead of xml.

Since the bean name can include values that are not allowed in bean id's, is there a method for doing this in annotations i.e. Component, Repository...?

Thanks


Yes, you can put the name of the bean directly in the annotation

@Repository("MyBeanNameHere")

But in most cases when you are using annotations that are @Components, then you are also using @Autowired, so bean names at that point become not necessary.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic