Autowiring spring bean by name using annotation

Viewed 80539

In Springs latest version, we can autowire a bean using annotation as @Autowired. This will autowire the bean using its type(or constructor, if applied on it). Is there any way I can use the @Autowired annotation based on the bean name which we were doing without annotation in Spring's XML file as autowire="byName"?

5 Answers

Use @Component("beanname") in the java class definition of your bean

Then while autowiring use JSR 330

@Inject @Named(Value="beanname")

Related