@TestController
public class TestController{
@GetMapping("/test")
public String test(){
return "Hello, world!";
}
}
@TestController
: 라우터 역할을 하는 애너테이션
: 클라이언트 요청에 맞는 메서드를 실행
: @Component 애너테이션처럼 취급됨
* 라우터 : HTTP 요청과 메서드를 연결하는 장치
// RestController.java 파일
@Target(ElmentType.Type)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Controller
@ResponeseBody
public @interface RestController{
@AliasFor(annotation = Controller.class)
String value() default "";
}
// Contoller.java 파일
@Target(ElmentType.Type)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Component
public @interface Controller{
@AliasFor(annotation = Component.class)
String value() default "";
}
RestController 안의 Controller에 Component 애너테이션이 포함되어 있기 때문에 Controller 애너테이션이 ComponentScan을 통해 빈으로 등록될 수 있음
'학습 기록 > 스프링 부트3 백엔드 개발자 되기[자바편]' 카테고리의 다른 글
[03장.1] 2. 스프링부트 프로젝트 디렉터리 구성 & main 디렉터리 구성 (0) | 2023.08.28 |
---|---|
[03장.1] 1. 카페와 빵집으로 이해하는 계층 (1) | 2023.08.28 |
[02장. 4] 1. @SpringBootApplication 이해하기 (0) | 2023.08.21 |
[02장.3] 4. 스프링 부터 3와 자바 버전 (0) | 2023.08.21 |
[02장. 3] 3. 자동구성 (0) | 2023.08.21 |