Reputation: 3433
I am using spring 3.x for my application. I used annotations to configure spring beans,
but in some scenarios i need to get object of a bean by its name. In XML based configuration i could do this by implementing BeanfactoryAware
and calling getbean("beanName")
. Is this possible in annotation based spring configuration. If so how can i use it, since I am not much aware of annotations.
Upvotes: 1
Views: 305
Reputation: 81
Try to use parameter of annotation
@Bean(name = "beanName")
@Service(value = "beanName")
If not specify value then Spring create bean with name of Java Naming Conventions:
@Service
class ExampleBean { }
in this case we have bean with name exampleBean.
And then
getBean("beanName") getBean("exampleBean")
Upvotes: 1