Skip to main content

Posts

Showing posts from July, 2016

Spring : Difference between @Autowired, @Inject and @Resource

Points To Remember @Inject is not a spring feature you need to include  javax inject dependency  in order to use @Inject. @Autowired is Spring annotation used to inject dependency just like @Inject. It use @Qualifier annotation to differentiate between the beans. @Resource is also Spring annotation, but it uses bean name to inject dependencies and differentiate between beans. Problem Statement :: Structure In order to show how @Autowired @Inject and @Resource annotations work  we will create 3 services Interface PersonService , this is the interface for all person related operations. Class EngineerService , this is the service that will do operations for engineer. Class ManagerService , this is the service that will do operations for manager. Here, both EngineerService and ManagerService implements PersonService.  Now we will try to add the services to a controller by different  ways to test how @Autowire , @Inject and @Resource will work. So the above structure looks like as