Annotations Flashcards

1
Q

What is the difference between @Component, @Controller, @Repository & @Service annotations?

A

@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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What do you understand by @Required annotation?

A
  • 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What do you understand by @Autowired annotation

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What do you understand by @RequestMapping annotation?

A
- 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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly