views:

26

answers:

1

Hi,

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

+1  A: 

@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

Bogdan
so repository does not provide any functionality am i right? What does role mean? for @controller there is something happening when we use it what is happening when we use repository?
mehmet6parmak
it actually does, it makes the annotated class eligible for DataAccessException translation.
Bogdan