springmvc事务失效或不能注入的原因

注入失败但事务失效配置:
如果dao和service层配置了拦截器,比如
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<property name="beanNames">
<value>*Service,*Dao</value>
</property>
<property name="interceptorNames">
<list>
<value>profilerInterceptor</value>
</list>
</property>
</bean>

那么service层扫描注解方式必须是:
<!-- 扫描注解service层 -->
<context:component-scan base-package="com.songdt.service.*" />
springmvc配置必须是:
<context:component-scan base-package="com.songdt">
    <context:include-filter type="regex" expression="com.songdt.web.action"/>
</context:component-scan>

否则会报异常:
org.springframework.beans.factory.BeanCreationException: Could not autowire field

但是以上配置又会使AspectJ配置的事务失效。
如果想事务不失效应配置如下:
springmvc配置:
<context:component-scan base-package="com.songdt.web.action"/>

那么service层扫描注解方式必须是:
<!-- 扫描注解service层 -->
<context:component-scan base-package="com.songdt.service" />
但是以上配置又会使dao和service层配置拦截器不可用,因为启动时会报注入失败异常

造成以上不能共用原因还有带查找

猜你喜欢

转载自songdiantao.iteye.com/blog/1054037