0

I'm trying to deploy a simple Spring Boot application. application.properties contains the following:

spring.datasource.name=MyDS
spring.datasource.username=user
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.xa.data-source-class-name=com.mysql.jdbc.jdbc2.optional.MysqlXADataSource
spring.datasource.password=passwd
spring.jpa.database=mysql
spring.jpa.database-platform=org.hibernate.dialect.HSQLDialect
spring.datasource.url=jdbc\:mysql\://host\:3306/mydb
hibernate.dialect: org.hibernate.dialect.MySQL5Dialect
entitymanager.packagesToScan: /

Upon deploying I get the following:

java.lang.IllegalStateException: Unable to create XADataSource instance from 'com.mysql.jdbc.jdbc2.optional.MysqlXADataSource'
        at org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration.createXaDataSourceInstance(XADataSourceAutoConfiguration.java:107)
        at org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration.createXaDataSource(XADataSourceAutoConfiguration.java:94)
        at org.springframework.boot.autoconfigure.jdbc.XADataSourceAutoConfiguration.dataSource(XADataSourceAutoConfiguration.java:76)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
        ... 47 more

I've only encountered this kind of exception when the XA DataSource was set to org.mysql.jdbc.MySQLDataSource. In that case setting it to com.mysql.jdbc.jdbc2.optional.MysqlXADataSource is supposed to do the trick. Any suggestions are welcome.

UPDATE: after bringing in the older versions of Atomikos in pom.xml I can choose between atomikos-util 3.8.0 in which case the spring-boot:run fails with java.lang.ClassNotFoundException: com.atomikos.util.Assert. If however I change the version to atomikos-util 4.0.0 or higher I get com.atomikos.diagnostics.Console.

András Hummer
  • 960
  • 1
  • 17
  • 35

2 Answers2

3
spring.datasource.xa.properties.driver-class-name=com.mysql.jdbc.Driver

You also need to tell which driver xa datasource will use

Muhammad Waqas
  • 367
  • 3
  • 13
1
@Bean
public DataSource dataSource() {
      DataSource dataSource = new DataSource();
      ....
      return dataSource;
}

This might do the trick

Y.Kaan Yılmaz
  • 612
  • 5
  • 18
  • I created the following bean: @Bean @ConfigurationProperties(prefix = "spring.datasource") public DataSource dataSource(){ return DataSourceBuilder.create().type(MysqlXADataSource.class).build(); } Now I get the following: `java.lang.ClassNotFoundException: com.atomikos.icatch.HeuristicMessage` despite Atomikos `transactions-jta` being already there in the pom.xml. – András Hummer Mar 17 '18 at 15:39