I make a basic project of javaweb, and add spring transaction configration on it, but it does not effect. before this, it work well. I searched a lot pages on net, those configurations are same as mine.
Expected result is nothing will be inserted, but a record was inserted.
Please help me find that where the problem is, thank u
my serviceimpl path is:com.lidaning.sys.user.service.UserInfoServiceImpl
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>
<tx:advice id="txAdvice" transaction-manager="txManager">
<tx:attributes>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut id="txPointcut" expression="execution(* com.lidaning.sys.user.service..*.*(..))" />
<aop:advisor pointcut-ref="txPointcut" advice-ref="txAdvice"/>
</aop:config>
@Override
public void insertUser(UserInfo u) {
u.setId("1");
u.setName("lidaning");
u.setPassword("***");
userInfoDao.insertUser(u);
userInfoDao.insertUser(u); //occur exception
}
I got the reason. Because spring loaded the serviceBean twice(spring, springMVC), and that caused service lost the characteristics of transactions. When I separated controller from applicationcontext and putt it in springMVC, it works.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.