Loading...
Spring Framework Reference Documentation 7.0.2의 Declaration의 한국어 번역본입니다.
아래의 경우에 피드백에서 신고해주신다면 반영하겠습니다.
감사합니다 :)
See equivalent in the Reactive stack
Servlet의 WebApplicationContext에서 표준 Spring 빈 정의를 사용하여 컨트롤러 빈을 정의할 수 있습니다. @Controller stereotype은 classpath에서 @Component 클래스를 탐지하고 그에 대한 빈 정의를 자동 등록하는 Spring의 일반적인 지원과 맞물려 자동 감지를 가능하게 합니다.
또한 어노테이션이 적용된 클래스가 웹 컴포넌트로서의 역할을 한다는 것을 나타내는 stereotype 역할을 합니다.
이러한 @Controller 빈의 자동 감지를 활성화하려면, 다음 예제에서 보듯이 Java 설정에 컴포넌트 스캐닝을 추가할 수 있습니다:
1@Configuration 2@ComponentScan("org.example.web") 3public class WebConfiguration { 4 5 // ... 6}
1@Configuration 2@ComponentScan("org.example.web") 3class WebConfiguration { 4 5 // ... 6}
1<beans xmlns="http://www.springframework.org/schema/beans" 2 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xmlns:context="http://www.springframework.org/schema/context" 4 xsi:schemaLocation=" 5 http://www.springframework.org/schema/beans 6 https://www.springframework.org/schema/beans/spring-beans.xsd 7 http://www.springframework.org/schema/context 8 https://www.springframework.org/schema/context/spring-context.xsd"> 9 10 <context:component-scan base-package="org.example.web"/> 11 12 <!-- ... --> 13 14</beans>
@RestController는 composed annotation으로, @Controller와 @ResponseBody로 메타 어노테이션되어 있으며, 타입 레벨 @ResponseBody 어노테이션을 모든 메서드가 상속받는 컨트롤러를 나타냅니다.
따라서 뷰 리졸루션 및 HTML 템플릿을 사용한 렌더링 대신 응답 본문에 직접 기록합니다.
See equivalent in the Reactive stack
일부 경우에는 런타임 시점에 AOP 프록시로 컨트롤러를 데코레이트해야 할 수도 있습니다. 한 가지 예는 컨트롤러에 직접 @Transactional 어노테이션을 두기로 선택하는 경우입니다. 이러한 경우, 특히 컨트롤러에 대해서는 클래스 기반 프록시를 사용할 것을 권장합니다. 이러한 어노테이션이 컨트롤러에 직접 적용된 경우에는 자동으로 그렇게 됩니다.
컨트롤러가 인터페이스를 구현하고 있고 AOP 프록시가 필요하다면, 클래스 기반 프록시를 명시적으로 설정해야 할 수도 있습니다. 예를 들어, @EnableTransactionManagement를 사용할 때 @EnableTransactionManagement(proxyTargetClass = true)로 변경할 수 있고, <tx:annotation-driven/>을 사용할 때 <tx:annotation-driven proxy-target-class="true"/>로 변경할 수 있습니다.
6.0 기준으로 인터페이스 프록시를 사용하는 경우, Spring MVC는 더 이상 인터페이스에 타입 레벨
@RequestMapping어노테이션만 있는 것만으로는 컨트롤러를 탐지하지 않는다는 점을 명심하십시오.<br>클래스 기반 프록시를 활성화하거나, 그렇지 않다면 인터페이스에도@Controller어노테이션이 있어야 합니다.
Annotated Controllers
Mapping Requests