kenzi

@Component? @Controller? 본문

Spring

@Component? @Controller?

kenzi 2022. 4. 13. 11:37

@Controller는 @Component(빈 객체)의 기능을 기본으로 갖고 있지만 

@RequestMapping과 같은 기능이 추가로 필요할 때 사용 

 

@Component는 그 자체로 그냥 빈 객체임을 표시해주는 것 

controller는 빈 객체이면서 url들어오면 메서드를 수행해야하므로 추가적으로 RequestMapping과 같은 기능이 필요함 => @Controller사용 

 


공식문서에 이거 한번 나왔던거 같은데 

 

 

https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#beans-annotation-config

 

Core Technologies

In the preceding scenario, using @Autowired works well and provides the desired modularity, but determining exactly where the autowired bean definitions are declared is still somewhat ambiguous. For example, as a developer looking at ServiceConfig, how do

docs.spring.io

찾았다

1.10.1. @Component and Further Stereotype Annotations

Spring provides further stereotype annotations: @Component, @Service, and @Controller. 

@Component is a generic stereotype for any Spring-managed component. 

@Repository, @Service, and @Controller are specializations of @Component for more specific use cases (in the persistence, service, and presentation layers, respectively).

Therefore, you can annotate your component classes with @Component, but, by annotating them with @Repository, @Service, or @Controller instead, your classes are more properly suited for processing by tools or associating with aspects.

For example, these stereotype annotations make ideal targets for pointcuts. @Repository, @Service, and @Controller can also carry additional semantics in future releases of the Spring Framework. 

 

 

 

 

https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#mvc-controller

 

Web on Servlet Stack

Spring Web MVC is the original web framework built on the Servlet API and has been included in the Spring Framework from the very beginning. The formal name, “Spring Web MVC,” comes from the name of its source module (spring-webmvc), but it is more com

docs.spring.io

여기서도 나온다

1.3.1. Declaration

The @Controller stereotype allows for auto-detection, aligned with Spring general support for detecting @Component classes in the classpath and auto-registering bean definitions for them.

It also acts as a stereotype for the annotated class, indicating its role as a web component.

 

 

'Spring' 카테고리의 다른 글

스프링 인코딩 필터  (0) 2022.04.14
java.lang.classnotfoundexception  (0) 2022.04.14
@ModelAttribute와 model.addAttribute  (0) 2022.04.08
스프링 mvc 수업정리(RESTful?url-pattern? 경로?)  (0) 2022.04.07
스프링 mvc흐름  (0) 2022.04.07
Comments