配置扫描@Controller注解的细节

来源:互联网 发布:暴风影音怎么关闭网络 编辑:程序博客网 时间:2024/05/21 17:25
<context:component-scan base-package="com.ssh.controller"> 
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/> 
</context:component-scan>


在第二种配置,不能把base-package="com.ssh",它是不仅仅扫描@Controller,会导致事务不起作用。
因为如果没有配置<context:component-scan>的use-default-filters属性,则默认为true,会自动扫描@Service和@Reposity,

而配置aop没有在springmvc配置文件中,从而造成新加载的bean覆盖了老的bean,造成事务失效。只要使用use-default-filters=“false”禁用掉默认的行为就可以了。

注:spring启动的容器是父容器,springmvc启动的容器是子容器。

子容器能访问父容器的资源,父容器不能访问子容器的资源

0 0
原创粉丝点击