在spring的applicationContext.xml中配置问题
正确的配置:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!--启动注解-->
<context:annotation-config />
<!-- base-package 注解所在的包根据自己的需要划分注解类使用的范围 -->
<context:component-scan base-package="main.com.talkweb">
<!--不再管理Controller 注解 因为它单独给mvc-servler.xml去管理-->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
</beans>
明明有启动注解,但有些注解还是没起作用
<!--启动注解-->
<context:annotation-config />
后来发现原因是:下面这句作与springMVC的controller注解的排除关注时,把扫描注解的返回局限了
原来 base-package=”main.com.talkweb.Controller”:
!-- base-package 注解所在的包根据自己的需要划分注解类使用的范围 -->
<context:component-scan base-package="main.com.talkweb.Controller">
<!--不再管理Controller 注解 因为它单独给mvc-servler.xml去管理-->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
现在的包范围 base-package=“main.com.talkweb”:
!-- base-package 注解所在的包根据自己的需要划分注解类使用的范围 -->
<context:component-scan base-package="main.com.talkweb">
<!--不再管理Controller 注解 因为它单独给mvc-servler.xml去管理-->
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
</context:component-scan>
刚学习会出现各种各样的问题,分享出来相互学习