Spring MVC framework provides different configuration elements that are helping or instructing the Spring container to effectively manage the beans and inject the beans when required.
1. <context:component-scan/> 있으면 <context:annotation-config/>필요없음.
- spring version2.5에 나왔다.
- context:component-scan element in the spring configuration file would eliminate the need for declaring all the beans in the XML files. (과거에는 XML file에 bean들 일일이 등록했어야 했다.)
- ex) <context:component-scan base-package="org.controller"/>
- 설정해준 package scan하여 bean들 생성해준다. ( 아래 표시 같은 어노테이션 class위에 붙여줘야한다.)
- @Component
- @Repository
- @Service
- @Controller
- 또한, it also resolve @Autowired and @Qualifier annotations. Therefore if you declare <context:component-scan>, is not necessary anymore declare <context:annotation-config> too.
2. <mvc:annotation-driven/>
- 이거 추가 없이 component-scan만 설정했을 경우 위의 설명과 같이 작동
- This tag would registers the HandlerMapping and HandlerAdapter required to dispatch requests to your @Controllers.
- 추가적인 defaults들은 아래 링크 참고
3. <context:annotation-config/>
- context:annotation-config is used for activating annotations in beans already registered in the application context
(no matter whether they were defined with XML or by package scanning).
- context:component-scan과 차이 : context:component-scan will also scan the packages for registering the beans to
application context.(IOC컨테이너) context:annotation-config will not search for the beans registration, this will
only activate the already registered beans in the context. (빈이 등록되어있는지 스캔하지 않고, 이미 등록되어있는 빈들의 관계를 해결하는데 쓰임 ex), setter injection, constructor injection
'Back-end > Spring-핵심& webMVC' 카테고리의 다른 글
SessionStatus, @SessionAttributes, @SessionAttribute (0) | 2023.01.01 |
---|---|
Jsp- jstl (0) | 2023.01.01 |
Web.xml, DispatcherServlet, ContextLoaderListener 각각의 역할 및 관계 (0) | 2022.12.30 |
DTO(DataTransferObject) vs. VO(Value Object) (0) | 2022.12.11 |
SpringBootServletInitializer (0) | 2022.12.10 |