context:component-scan的一点记录

2019-08-21  本文已影响0人  有时右逝

前言

目前项目一直使用的ssm结构,相对springboot存在,ssm配置起来的确繁琐。但是有个好处,对spring的一些原理能理解更深一点。这里记录一下刚刚的心得

配置

spring.xml

<context:component-scan base-package="com.wuwenfu.aily">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>

spring-mvc.xml


    <context:component-scan base-package="com.wuwenfu.aily.controller" >

        
    </context:component-scan>

解释

image.png

其中经常使用的过滤器是

        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>

通常表示spring.xml不扫描Controller,而交给spring-mvc.xml来扫描。否则会导致2次注册。

上一篇 下一篇

猜你喜欢

热点阅读