what are @Repository and @Autowired used for. (Spring)

mehmet6parmak picture mehmet6parmak · Oct 21, 2010 · Viewed 53.8k times · Source

I am learning java for 3 months and sometimes i can not understand the usage purpose of something.

one topic was dependency injection and spring beans i figured out the finally =)

now i confused with the two annotations @Autowired and @Repository. First What does Autowiring mean? then Why should i use them and what is the difference between using them and not using?

Also today i tried to use hibernate in a spring mvc project and i had to search for about 15(cause of class not found errors) jar files beacuse of the dependencies of other jar files used in the project. is this had to be this way? this makes learning java very hard for the beginners

thanks...

Answer

Bogdan picture Bogdan · Oct 21, 2010

@Repository is an annotation that marks the specific class as a Data Access Object, thus clarifying it's role. Other markers of the same category are @Service and @Controller

@Autowired is an annotation with a completely different meaning: it basically tells the DI container to inject a dependency. More info at http://apollo89.com/java/spring-framework-2.5.3/api/org/springframework/beans/factory/annotation/Autowired.html
Edit More info at tutorialpoint
or docs.spring.io