Announcement Announcement Module
No announcement yet.
what's the different between @Repository and @Component? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • what's the different between @Repository and @Component?

    As the title,anyone can help me?Thanks.

  • #2
    @Repository is a specialization of @Component

    @Repository is used to mark classes that has the role of a repository (like the DAO)
    the use of this marker is the automatic traslation of exception
    (try to look in the official documentation the "Exception Traslation"

    @Component is only the more generic stereotype for any Spring managed component

    Therefor you can annotate your class with @component, but annotating with the more specific marker (@Repository,@Component,@Service,@Controller), your classes are more properly suited for processing by tool or associating with aspect
    Last edited by AleSky; Mar 1st, 2012, 04:28 AM. Reason: put link to official documentation