0% found this document useful (0 votes)
25 views1 page

Use Stereotype Annotations As Much As Possible When Employing Annotation

Spring annotation based configuration offers several annotations like @Controller, @Service, and @Repository that inherit from @Component. These annotations provide additional functionality like exception handling and transaction management that @Component does not.

Uploaded by

vvx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views1 page

Use Stereotype Annotations As Much As Possible When Employing Annotation

Spring annotation based configuration offers several annotations like @Controller, @Service, and @Repository that inherit from @Component. These annotations provide additional functionality like exception handling and transaction management that @Component does not.

Uploaded by

vvx
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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