问题描述
我有一个用@Transactional(rollbackFor = CustomerRollBackException.class)注释的方法,当我在嵌入式tomcat中对其进行测试时,它可以按预期工作。 但是,我已将其部署在jboss wildfly上,并且当抛出异常时,相同的方法不会执行回滚。 您是否知道是否需要在jboss上进行任何配置?
@Override
@Transactional(rollbackFor = CustomerRollBackException.class)
public void importGenericTable(SheetDTO sheetDTO) throws Exception {
// String tableName,List<Object> rows,UserDTO user
Iterator iterator;
String tableName = sheetDTO.getTableName();
....
try{
..
} catch (ParseException | PersistenceException | sqlGrammarException | ConstraintViolationException e) {
logger.error("importGenericTable. Error " + e);
throw new CustomerRollBackException("E_NPRO_UTIL_IMPORT_0001:" + (countRows + 2));
} catch (CustomerNotFoundException e) {
throw new CustomerRollBackException(e.getMessage());
} catch (Exception e) {
throw new CustomerRollBackException("error desconocido");
}
..
它正在进入第一个捕获并抛出CustomerRollBackException,并且回滚未执行。
解决方法
我认为对于jboss,您应该改用rollbackOn
,解决方案: 在jboss上配置数据源,并在应用程序中使用 spring.datasource.jndi-name = java:/ XXXX 代替:
spring.datasource.url= jdbc:
spring.datasource.username=
spring.datasource.password=