Db2 Don';t通过注释打开Spring事务

Db2 Don';t通过注释打开Spring事务,db2,websphere,spring-transactions,Db2,Websphere,Spring Transactions,在我的应用程序中,我有两个transactionManager,创建方式如下: <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <qualifier value="exec"/> <property name="dataSource" ref="execDataSource"/> </bean>

在我的应用程序中,我有两个transactionManager,创建方式如下:

<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <qualifier value="exec"/>
    <property name="dataSource" ref="execDataSource"/>
</bean>
<bean id="txManagerAdmin" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <qualifier value="admin"/>
    <property name="dataSource" ref="adminDataSource"/>
</bean>
这里是我的带有事务注释的方法:

@Target({ElementType.METHOD, ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Transactional(value="admin", rollbackFor=NullPointerException.class, propagation = Propagation.REQUIRES_NEW, isolation = Isolation.DEFAULT)
public @interface AdminTx {

}
@AdminTx
    @Override
    public UaCatalogDTO addUa(UaDTO uaDTO) throws TechnicalException {
        MapSqlParameterSource namedParameterSource = new MapSqlParameterSource();
        mapAllUaFields(uaDTO, namedParameterSource);
        try {
            jdbcTemplate.update(SqlQueries.ADD_UA, namedParameterSource);
        } catch (DuplicateKeyException e) {
            throw new TechnicalException(e, "ADM001");
        }
                if (1==1) //due to compiler
                throw new NullPointerException(); //to test the transaction is working
    }
由于有接口,此方法从另一个类调用。bean是由Spring@Autowired注释注入的。
jdbcTemplate
对象是使用以下代码创建的:

@Autowired
@Qualifier("adminDataSource")
public void setDataSource(DataSource dataSource) {
    this.jdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}
我的问题是当我执行
jdbcTemplate.update()
行时,如果我检查数据库,数据已经存在。另外,即使我抛出NullPointerException,数据仍保留在数据库中

经过一些搜索,我发现我们可以调用
TransactionSynchronizationManager.isActualTransactionActive()
,它返回我
false
值。 所以我明白我的注释什么都不做,但我不明白为什么


我在Websphere服务器上运行,数据库是DB2。

经过一些搜索,我终于找到了问题,所以如果有人感兴趣,我会发布它: 它是Spring生成的bean,没有使用特定于XML的声明,而是使用Spring扫描

当我试图在XML文件中声明bean,然后用
Autowired
Qualifier
将其注入类中时,事务最终打开并关闭

顺便说一下,我不知道原因

@Autowired
@Qualifier("adminDataSource")
public void setDataSource(DataSource dataSource) {
    this.jdbcTemplate = new NamedParameterJdbcTemplate(dataSource);
}