我们公司用的spring3.2+spring mvc3+mybatis3.1的框架,这两天在添加事务管理的时候,发现了一个怪现象,跟网上的说法有点不大一样,下面说一下我碰到的情况:
我在applicationContext.xml里面自动扫描bean(包括了controller,service,autowired),
<context:component-scan base-package="com.kimho">,
在springMVC-servlet.xml里面也扫描了全部bean,果然定义的声明式事务失效, 后来按照网上的说法将springMVC-servlet.xml修改如下:
<context:component-scan base-package="com.kimho">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
</context:component-scan> applicationContext.xml修改如下:
<context:component-scan base-package="com.kimho">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan> 这样就将所要控制的service层bean放在了我声明事务的applicationContext.xml文件里,可是测试了事务还是没有回滚。
后来不用声明式,用了注解
<tx:annotation-driven transaction-manager="KimHoTransactionManager"/>就可以了,而且就算在springMVC-servlet.xml里面扫面全部bean,事务也是管用的,求指点!java webspring事务mybatisBean
我在applicationContext.xml里面自动扫描bean(包括了controller,service,autowired),
<context:component-scan base-package="com.kimho">,
在springMVC-servlet.xml里面也扫描了全部bean,果然定义的声明式事务失效, 后来按照网上的说法将springMVC-servlet.xml修改如下:
<context:component-scan base-package="com.kimho">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
</context:component-scan> applicationContext.xml修改如下:
<context:component-scan base-package="com.kimho">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
</context:component-scan> 这样就将所要控制的service层bean放在了我声明事务的applicationContext.xml文件里,可是测试了事务还是没有回滚。
后来不用声明式,用了注解
<tx:annotation-driven transaction-manager="KimHoTransactionManager"/>就可以了,而且就算在springMVC-servlet.xml里面扫面全部bean,事务也是管用的,求指点!java webspring事务mybatisBean
修改后扫描的是Controller
你扫描部分还没有弄清楚的话直接用<mvc:annotation-driven/>这个直接声明所有注解支持。
还有。 applicationContext.xml是spring的默认配置文件名。 你如果要用这个做springMVC的配置文件的话。要特殊声明。
http://www.blogjava.net/robbie/archive/2009/04/05/264003.html