Java/SPRING

스프링 프레임워크 [Spring Framework] @어노텐션을 이용한 Controller class 자동 스캔

백엔드 신입사원( soft 5.10 입사) 2021. 12. 22. 17:42
반응형

@Controller Annotation은 @Component Annotation과 처럼 컴포넌트 스캔 대상

 

그래서, context:component-scan 태그를 이용해서 @Controller Annotation이 적용된 컨트롤러 Class를 자동으로 로딩할 수 있다.

<?xml version="1.0" encoding="UTF-8"?>  
  
<beans xmlns="[http://www.springframework.org/schema/beans"](http://www.springframework.org/schema/beans%22)  
xmlns:context="[http://www.springframework.org/schema/context"](http://www.springframework.org/schema/context%22)  
xmlns:p="[http://www.springframework.org/schema/p"](http://www.springframework.org/schema/p%22)  
xmlns:xsi="[http://www.w3.org/2001/XMLSchema-instance"](http://www.w3.org/2001/XMLSchema-instance%22)  
xsi:schemaLocation="[http://www.springframework.org/schema/beans](http://www.springframework.org/schema/beans)  
[http://www.springframework.org/schema/beans/spring-beans-3.0.xsd](http://www.springframework.org/schema/beans/spring-beans-3.0.xsd)  
[http://www.springframework.org/schema/context](http://www.springframework.org/schema/context)  
[http://www.springframework.org/schema/context/spring-context-3.0.xsd">](http://www.springframework.org/schema/context/spring-context-3.0.xsd%22%3E)  
  
<context:component-scan base-package="컨트롤러 주소" />  
</beans>
반응형