我以随机的方式得到以下错误。它最初不会抛出错误,但一段时间后会抛出错误。一旦我重新启动服务器,一切都会重置,并且不会抛出错误。
XA资源' XXXXAtomikosDataSource':简历适用于XID' 31302E3137382E36382E3235302E746D30303031353030303138:31302E3137382E36382E3235302E746D3135'引发-7:XA资源不可用
我正在使用以下依赖项。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jta-atomikos</artifactId>
<version>1.4.2.RELEASE</version>
</dependency>
配置bean
@Bean(name= "userTransaction")
public UserTransaction userTransaction() throws Throwable {
UserTransactionImp userTransactionImp = new UserTransactionImp();
return userTransactionImp;
}
@Bean
@Primary
public TransactionManager atomTransactionManager() throws Throwable {
UserTransactionManager userTransactionManager = new UserTransactionManager();
userTransactionManager.setForceShutdown(false);
return userTransactionManager;
}
@Bean("atomikosTransactionManager")
public PlatformTransactionManager platformTransactionManager() throws Throwable {
UserTransaction userTransaction = userTransaction();
TransactionManager transactionManager = atomTransactionManager();
JtaTransactionManager jtaTransactionManager = new JtaTransactionManager(userTransaction, transactionManager);
jtaTransactionManager.setAllowCustomIsolationLevels(true);
jtaTransactionManager.setDefaultTimeout(1000);
return jtaTransactionManager;
}
@Bean(name = "atomikosDataSources")
public Map<String, DataSource> atomikosDataSources(PropertiesFactoryBean databaseProperties, Environment environment, BcusDefaultEncrytor bcusDefaultEncrytor) throws SQLException, IOException {
List<String> databases= Collections.list(databaseProperties.getObject().propertyNames()).stream().map(key->key.toString()).filter(key-> key.contains("url")).collect(Collectors.toList());
Map<String, DataSource> collect = databases.stream().collect(Collectors.toMap(dbName -> dbName.split("\\.")[0].toUpperCase() + "AtomikosDataSource", dbName -> {
OracleXADataSource dataSource = null;
try {
dataSource = new OracleXADataSource();
dataSource.setURL(environment.getProperty(dbName));
dataSource.setUser(environment.getProperty("database.username"));
dataSource.setPassword(bcusDefaultEncrytor.decryptQAPassword(environment.getProperty("database.password")));
}
catch (SQLException e)
{
LOG.error(
"DatabaseConditionException [errorCode= Error while configuring atomikos data sources- Could not OracleXADataSource object, errorMessage= {} ]",
e.getMessage());
}
catch (Exception e) {
LOG.error(
"DatabaseConditionException [errorCode= Error while configuring atomikos data sources- Could not decrypt QA Password make sure you have proper **QA** Encryption password in your folder, errorMessage= {} ]",
e.getMessage());
}
AtomikosDataSourceBean xaDataSource = new AtomikosDataSourceBean();
xaDataSource.setXaDataSource(dataSource);
xaDataSource.setUniqueResourceName(dbName.split("\\.")[0].toUpperCase() + "AtomikosDataSource");
xaDataSource.setPoolSize(5);
return xaDataSource;
}));
return collect;
}
答案 0 :(得分:0)
问题是因为spring-boot-starter-jta-atomikos中的atomikos 3.9.3版本中的一个错误带来:1.4.2.RELEASE。
将版本更新为atomikos 4.0.4后,问题就解决了。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jta-atomikos</artifactId>
<exclusions>
<exclusion>
<artifactId>transactions-jdbc</artifactId>
<groupId>com.atomikos</groupId>
</exclusion>
<exclusion>
<artifactId>transactions-jms</artifactId>
<groupId>com.atomikos</groupId>
</exclusion>
<exclusion>
<artifactId>transactions-jta</artifactId>
<groupId>com.atomikos</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.atomikos</groupId>
<artifactId>transactions-jms</artifactId>
<version>${transaction.version}</version>
</dependency>
<dependency>
<groupId>com.atomikos</groupId>
<artifactId>transactions-jta</artifactId>
<version>${transaction.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jta_1.0.1B_spec</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.atomikos</groupId>
<artifactId>transactions-jdbc</artifactId>
<version>${transaction.version}</version>
</dependency>