【发布时间】:2015-01-29 07:24:47
【问题描述】:
我的应用程序当前使用 Spring 的 JdbcTemplate 和 @Transaction 注释进行事务处理。
我有一个在单个事务上调用 Web 服务 的方法,我设计它以便 Web 服务的异常将回滚事务中的所有数据库更改。
我的问题:如何在调用我的网络服务之前刷新数据库更改?
非常感谢
@Autowired
private MyDao dao;
@Transactional
@Override
public void myMethod() {
.....
dao.saveThis(myObjectToSaveIsNotAnIssue);
// I need to FLUSH here in order for my web service to "see" the saved object
callWebservice();
}
我的弹簧配置:
<context:component-scan base-package="com.xxx.xxx" />
<context:annotation-config />
<!-- proxy-target-class is set to true to use transactional scope -->
<tx:annotation-driven proxy-target-class="true" transaction-manager="tomcatTransactionManager" />
<bean id="sybaseDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:comp/env/jdbc/xxx"/>
<property name="lookupOnStartup" value="true"/>
<property name="proxyInterface" value="javax.sql.DataSource"/>
</bean>
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
<property name="dataSource" ref="sybaseDataSource"/>
</bean>
<!-- Transaction Manager -->
<bean id="tomcatTransactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="sybaseDataSource" />
</bean>
【问题讨论】:
标签: java spring transactions jdbctemplate