spring對應配置文件為:
<!-- 配置自動掃描的包,此時要排除Controller --> <context:component-scan base-package="com.lw"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan>
springmvc對應的配置文件為:
<!-- user-default-filters 與 include-filter搭配使用 實現僅僅掃描Controller注解 --> <context:component-scan base-package="com.lw" use-default-filters="false"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan>
注:屬性user-default-filters官方介紹:
Attribute : use-default-filters Indicates whether automatic detection of classes annotated with @Component, @Repository, @Service, or @Controller should be enabled. Default is "true".