Loading...
Spring Framework Reference Documentation 7.0.2의 @Controller의 한국어 번역본입니다.
아래의 경우에 피드백에서 신고해주신다면 반영하겠습니다.
감사합니다 :)
@ControllerSee equivalent in the Servlet stack
표준 Spring bean 정의를 사용하여 controller bean을 정의할 수 있습니다.
@Controller stereotype은 자동 감지를 가능하게 하며, classpath에서 @Component 클래스를
감지하고 그들에 대한 bean 정의를 자동 등록하는 Spring 일반 지원과
정렬되어 있습니다.
또한 어노테이션이 적용된 클래스에 대한 stereotype으로 작동하여, 해당 클래스가 web 컴포넌트 역할을 한다는 것을 나타냅니다.
이러한 @Controller bean의 자동 감지를 가능하게 하려면, 다음 예제에서 보듯이
Java 설정에 컴포넌트 스캐닝을 추가하면 됩니다:
1@Configuration 2@ComponentScan("org.example.web") // (1) 3public class WebConfiguration { 4 5 // ... 6} 7// Copied!
| 1 | org.example.web 패키지를 스캔합니다. |
1@Configuration 2@ComponentScan("org.example.web") // (1) 3class WebConfiguration { 4 5 // ... 6} 7// Copied!
| 1 | org.example.web 패키지를 스캔합니다. |
@RestController는 composed annotation으로,
자체가 @Controller 및 @ResponseBody로 메타 어노테이션되어 있으며, 이는 controller의
모든 메서드가 타입 레벨 @ResponseBody 어노테이션을 상속하여, view resolution 및 HTML 템플릿으로의
렌더링과는 달리 response body에 직접 쓰는 것을 의미합니다.
See equivalent in the Servlet stack
일부 경우에는 런타임에 AOP 프록시로 controller를 데코레이트해야 할 수도 있습니다.
한 가지 예로, controller에 직접 @Transactional 어노테이션을 사용하는 경우가 있습니다.
이러한 경우, 특히 controller에 대해서는 클래스 기반 프록시를 사용할 것을 권장합니다. 이는 이러한 어노테이션이 controller에 직접 있는 경우 자동으로 적용됩니다.
controller가 인터페이스를 구현하고 있고 AOP 프록시가 필요하다면, 클래스 기반 프록시를
명시적으로 구성해야 할 수도 있습니다. 예를 들어, @EnableTransactionManagement를 사용할 때
@EnableTransactionManagement(proxyTargetClass = true)로 변경할 수 있고,
<tx:annotation-driven/>을 사용할 때는 <tx:annotation-driven proxy-target-class="true"/>로
변경할 수 있습니다.
| Note | 6.0부터는 인터페이스 프록시를 사용할 때, Spring WebFlux는 더 이상 인터페이스에 있는 타입 레벨 @RequestMapping 어노테이션만을<br>기반으로 controller를 감지하지 않는다는 점을 유념해야 합니다.<br>클래스 기반 프록시를 활성화하거나, 그렇지 않다면 인터페이스에도<br>@Controller 어노테이션이 있어야 합니다. |
Annotated Controllers
Mapping Requests