Spring数据源事务管理器不回滚
<!-- Data source definition -->
<bean id="dataSourceWebsube"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url.websube}"
p:username="${jdbc.username.websube}" p:password="${jdbc.password.websube}" />
<bean id="jdbcTemplateWebsube" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSourceWebsube" />
</bean>
<!-- Transaction manager, actually this one is useless since the Transaction Manager Bean is already called transactionManager -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSourceWebsube" />
</bean>
public class Test
{
@Transactional
public static void testTranscational(JdbcTemplate jdbcTmpl)
{
String sql = null;
sql = "INSERT INTO NBSM.INT_RTLNOUTBOUND_PRODUCTS(BASEPRODUCTCODE)VALUES(1)";
jdbcTmpl.update(sql);
throw new RuntimeException();
}
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("application-context.xml");
JdbcTemplate jdbcTmpl = (JdbcTemplate) ctx.getBean("jdbcTemplateWebsube");
testTranscational(jdbcTmpl);
}
}
你好,
我正在尝试测试 spring 的事务管理功能,但我无法让它工作。我已经尝试解决这个问题几个小时了,但没有成功。
上面你可以看到相关的配置xml定义和dao测试类。即使当我使用调试级别进行日志记录时,也没有回滚机制的足迹。
任何帮助将不胜感激
<!-- Data source definition -->
<bean id="dataSourceWebsube"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url.websube}"
p:username="${jdbc.username.websube}" p:password="${jdbc.password.websube}" />
<bean id="jdbcTemplateWebsube" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="dataSourceWebsube" />
</bean>
<!-- Transaction manager, actually this one is useless since the Transaction Manager Bean is already called transactionManager -->
<tx:annotation-driven transaction-manager="transactionManager"/>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSourceWebsube" />
</bean>
public class Test
{
@Transactional
public static void testTranscational(JdbcTemplate jdbcTmpl)
{
String sql = null;
sql = "INSERT INTO NBSM.INT_RTLNOUTBOUND_PRODUCTS(BASEPRODUCTCODE)VALUES(1)";
jdbcTmpl.update(sql);
throw new RuntimeException();
}
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("application-context.xml");
JdbcTemplate jdbcTmpl = (JdbcTemplate) ctx.getBean("jdbcTemplateWebsube");
testTranscational(jdbcTmpl);
}
}
Hello,
I'm trying to test spring's transaction management capabilities but I cannot get it to work. I have been trying to solve it for hours but no luck.
Above you can see the related config xml definitions and the dao test class. Even when I use debug level for logging, there's no footprint of the rolling back mechanism.
Any help would be greatly appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为 Spring AOP 只能:
a)和b)是你的错误,你需要修复它。 -- 为了克服 c) 的问题,我强烈用 AspectJ 编译时挥手替换 Spring AOP。
如果我是对的,即使是事务处理(由
@Transational
)也一定无法正常工作。需要由其他人检查:
我从来没有看到
@Transactional
与JdbcTemplate
结合使用,所以我怀疑这是否有效 - 但我可能错了。It is because of Spring AOP can only:
a) and b) are your faults, you need to fix it. -- to overcome the problem of c) I strongly replace Spring AOP by AspectJ compile time waving.
If I am right, even the transaction handling (by
@Transational
must not be working.Need to be checked by someone else:
I have never seen
@Transactional
in combination withJdbcTemplate
, so I have doubt if this is working at all. -- But may I am wrong.