You are on page 1of 1

Spring annotation based configuration offers several annotations, like @Controller, @Service , @Repository

and so on. They all

inherit from @Component annotation as well. Although it is possible to create beans with only using
@Component annotation,

you will be missing some functionality which becomes available on your beans when they are defined with
appropriate stereo

type annotations.

For example, @Repository annotation helps handling of Hibernate or JPA specific exceptions and converting
them into Spring

specific DataAccessExceptions. @Controller annotation signals to DispatcherServlet that, it contains handler


methods with

@RequestMapping annotation. Although @Service annotation doesn’t make all of the public methods
transactional in a service

bean - like session beans in EJBs, it is just a matter of defining an annotation which brings those @Service
and @Transactional

annotations together, or write an aspect to achieve similar behavior.

@Controller

public class SecurityController {

private SecurityService securityService;

@Autowired

public void setSecurityService(SecurityService securityService) {

this.securityService = securityService;

//...

@Service

public class SecurityServiceImpl implements SecurityService {

@Autowired

private SecurityDao securityDao;

//...

You might also like