StereoType Annotations Flashcards

1
Q

@Component

A

The most general stereotype annotation, used to denote a class as a Spring-managed component.It’s typically used when a class doesn’t specifically belong to one of the other roles like a service or controller.

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

What is

A

stereotype annotations are special annotations that indicate a class is a Spring-managed component with a specific role within the application’s architecture

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

@Service

A

Specialization of @Component, specifically intended for service layer classes.

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

@Repository

A

Provides additional persistence-related exception handling, allowing for the conversion of database-related exceptions into Spring’s DataAccessException

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

@Controller

A

Typically used for classes that handle incoming HTTP requests and return views or responses.
Often paired with @RequestMapping methods to handle specific HTTP routes.

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

@RestController

A

Combines @Controller and @ResponseBody.
Typically used for RESTful web services, returning JSON or XML responses instead of views.
@RestController
public class MyRestController {
@GetMapping(“/api/greet”)
public String greet() {
return “Hello, RESTful World!”;
}
}

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

Working

A

When Spring scans for beans using @ComponentScan, it looks for classes annotated with any stereotype annotation. Once detected, these classes are registered in the application context and managed as Spring beans. This automatic registration enables dependency injection and supports Spring’s inversion of control (IoC) capabilities.

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