Tom Sebastian
Tom Sebastian

Reputation: 3433

getting annotation based bean using BeanfactoryAware

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

Answers (1)

Gwaeron
Gwaeron

Reputation: 81

Try to use parameter of annotation

  1. @Bean(name = "beanName")

  2. @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

Related Questions