Annotations Flashcards
What is the difference between @Component, @Controller, @Repository & @Service annotations?
@Component: generic stereotype and can be used across application
@Controller: Used to annotate classes at presentation layer level like in spring MVC
@Service: used to annoate classes at a service layer level
@Repository: Used to annotate classes at a persistence layer that acts as a database repository
What do you understand by @Required annotation?
- applied to bean property setter method
- indicates that at the configuration time the affected bean property should be populaed in XML configuration file, otherwise throw a BeanInitializationException
What do you understand by @Autowired annotation
the @Autowired annotation provides more accurate control over where and how autowiring should be done. Th @Autowired annotation is used to autowire bean on setter methods, constructor, a property or methods with arbitrary names and/or multiple argumentos
What do you understand by @RequestMapping annotation?
- can be applied at both levels: class level: maps the URL of the request Method level: maps the URL as well as HTTP request method