(1)只在applicationContext.xml中配置以下web
<context:component-scan base-package="com.login" />
启动正常,可是任何请求都不会被拦截,简而言之就是@Controller失效spring
(2)只在spring-servlet.xml中配置上述配置express
启动正常,请求也正常,可是事务失效,也就是不能进行回滚app
(3)在applicationContext.xml和spring-servlet.xml中都配置上述信息spa
启动正常,请求正常,也是事务失效,不能进行回滚code
(4)在applicationContext.xml中配置以下component
<context:component-scan base-package="com.login"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan>
在spring-servlet.xml中配置以下orm
<context:component-scan base-package="com.login.web" />
此时启动正常,请求正常,事务也正常了。xml
结论:在spring-servlet.xml中只须要扫描全部带@Controller注解的类,在applicationContext中能够扫描全部其余带有注解的类(也能够过滤掉带@Controller注解的类)。事务
具体原理:参考spirng源码。。。