1. 程式人生 > >spring mvc中掃描的配置程式碼

spring mvc中掃描的配置程式碼

mvc:annotation-driven

<mvc:annotation-driven /> :確定呼叫哪個controller的哪個方法來處理當前請求。如果沒有回找不到@RequestMapping指定的路徑

context:annotation-config

掃描的註解如下:@Autowired,@Resource 、@PostConstruct、@PreDestroy,@PersistenceContext,@Required。

context:component-scan

<context:annotation-config />:context:component-scan做了context:annotation-config要做的事情,還額外支援@Component,@Repository,@Service, @Controller @RestController, @ControllerAdvice, and @Configuration 註解。
所以配置context:component-scan就不需要配置context:annotation- config/

use-default-filters=“false”,不使用預設過濾器(所有包都不自動掃描),需要<context:include-filter type=“annotation” expression=“org.springframework.stereotype.Controller”,指定只掃描的包。

     <context:component-scan base-package="test.*.controller" use-default-filters="false">        
            <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>     
            <context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/> 
     </context:component-scan>

<context:exclude-filter type=“annotation” expression=“org.springframework.stereotype.Controller”/>,全部包都掃描,除了標籤裡面配置的。

      <context:component-scan base-package="test.*">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
        <context:exclude-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
      </context:component-scan> 


轉載於:
https://blog.csdn.net/qwe5810658/article/details/74343228
https://blog.csdn.net/baidu_21780935/article/details/60959510
https://blog.csdn.net/j080624/article/details/60883328