I would like to emphasize one comment from @Jules on this answer to this question. The comment brings a useful link: Spring Injection with @Resource, @Autowired and @Inject. I encourage you to read it entirely, however here is a quick summary of its usefulness:
@Autowired
and @Inject
@Resource
Explicitly name your component [@Component("beanName")]
Use @Resource
with the name
attribute [@Resource(name="beanName")]
@Qualifier
?Avoid @Qualifier
annotations unless you want to create a list of similar beans. For example you may want to mark a set of rules with a specific @Qualifier
annotation. This approach makes it simple to inject a group of rule classes into a list that can be used for processing data.
Scan specific packages for components [context:component-scan base-package="com.sourceallies.person"]
. While this will result in more component-scan
configurations it reduces the chance that you’ll add unnecessary components to your Spring context.
Reference: Spring Injection with @Resource, @Autowired and @Inject