-1

I am trying to learn Spring in Detail so in my sample I having a DAO

@Repository
public class EmployeeDAOImpl implements EmployeeDAO {
    ...
}

it is working fine, but the same with @Component too working fine without any issue

@Component
public class EmployeeDAOImpl implements EmployeeDAO {
    ...
}

So why do I want to mark my class with @Repository, and advantages there other than stereotype for persistence layer?

  • I would never agree with downvoter, there is something more we get when we annotate a class with `@Repository`, let me find the answer – Suganthan Madhavan Pillai Apr 15 '15 at 17:04
  • A class annotated with @Repository is eligible for Spring `DataAccessException` translation when used in conjunction with a `org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor` `PersistenceExceptionTranslationPostProcessor`. – Suganthan Madhavan Pillai Apr 15 '15 at 17:10

1 Answers1

4

Look at the source code of Repository that is also a Component

@Component
public @interface Repository { ... }

It's just there to make clear the purpose of the component/bean.

In the same way Service and Controller are also a Component that is used for services and controllers.

Braj
  • 46,415
  • 5
  • 60
  • 76