<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启动的容器是子容器。
子容器能访问父容器的资源,父容器不能访问子容器的资源