I am trying to boot up a spring application with Atomikos maven dependency
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jta-atomikos</artifactId>
</dependency>
Am also autowiring as following
@Autowired
JtaTransactionManager jtaTransactionManager;
application.yaml file is as follows
spring:
mvc:
throw-exception-if-no-handler-found: true
resources:
add-mappings: false
jta:
atomikos:
connectionfactory:
ignore-session-transacted-flag: false
unique-resource-name: xa.amq
min-pool-size: 10
max-pool-size: 20
datasource:
unique-resource-name: xa.db
min-pool-size: 10
max-pool-size: 20
test-query: "select 1"
properties:
default-jta-timeout: 50000
datasource:
url: jdbc:mysql://mydatabasehost:3306/test
driverClassName: com.mysql.jdbc.Driver
username: test
password: test
initialization-mode: always
It starts fine with above yaml configurations.
However, for my use case, I want my transaction manager to skip using the default spring datasource and instead I want to dynamically register datasource beans after the start up. I wanted to know if that is possible. If I remove my datasource settings from above yaml file, I get following error
15:15:19.322 [main] WARN com.atomikos.jdbc.AtomikosXAConnectionFactory - XAConnectionFactory: failed to create pooled connection - DBMS down or unreachable?
java.sql.SQLException: Database not available
at org.apache.derby.jdbc.BasicEmbeddedDataSource40.setupResourceAdapter(Unknown Source)
at org.apache.derby.jdbc.EmbeddedXADataSource.getXAConnection(Unknown Source)
at com.atomikos.jdbc.AtomikosXAConnectionFactory.createPooledConnection(AtomikosXAConnectionFactory.java:28)
at com.atomikos.datasource.pool.ConnectionPool.createPooledConnection(ConnectionPool.java:98)
at com.atomikos.datasource.pool.ConnectionPool.addConnectionsIfMinPoolSizeNotReached(ConnectionPool.java:86)
at com.atomikos.datasource.pool.ConnectionPool.init(ConnectionPool.java:60)
at com.atomikos.datasource.pool.ConnectionPool.<init>(ConnectionPool.java:49)
at com.atomikos.datasource.pool.ConnectionPoolWithConcurrentValidation.<init>(ConnectionPoolWithConcurrentValidation.java:23)
at com.atomikos.jdbc.AbstractDataSourceBean.init(AbstractDataSourceBean.java:294)
at org.springframework.boot.jta.atomikos.AtomikosDataSourceBean.afterPropertiesSet(AtomikosDataSourceBean.java:49)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:307)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:277)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1251)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1171)
at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:857)
at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:760)