title: Configuring a XADataSource for Spring-Boot
body: <p>I am doing an integration test against a 11G Oracle Database. I was getting an error saying:</p>
  
  <pre><code>Caused by: java.lang.NoClassDefFoundError: com/arjuna/ats/jbossatx/jta/RecoveryManagerService
  </code></pre>
  
  <p>So I added:</p>
  
  <pre><code>        &lt;dependency&gt;
              &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;
              &lt;artifactId&gt;spring-boot-starter-jta-narayana&lt;/artifactId&gt;
              &lt;version&gt;1.4.1.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
  </code></pre>
  
  <p>to my pom file and the error went away, but now I get an error saying:</p>
  
  <pre><code>  Caused by: java.lang.NoSuchFieldError: XADataSource
      at org.springframework.boot.jta.narayana.NarayanaDataSourceBean.getConnection(NarayanaDataSourceBean.java:58) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
      at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:254) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:228) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:207) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:207) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
      at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
      at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
      ... 44 common frames omitted
  </code></pre>
  
  <p>When I go to the class <code>(NarayanaDataSourceBean.java:58)</code> I see these two methods are unable to resolve XADataSource.</p>
  
  <pre><code>@Override
      public Connection getConnection() throws SQLException {
          Properties properties = new Properties();
          properties.put(TransactionalDriver.XADataSource, this.xaDataSource); //cannot resolve XADataSource
          return ConnectionManager.create(null, properties);
      }
  
      @Override
      public Connection getConnection(String username, String password)
              throws SQLException {
          Properties properties = new Properties();
          properties.put(TransactionalDriver.XADataSource, this.xaDataSource); //cannot resolve XADataSource
          properties.put(TransactionalDriver.userName, username);
          properties.put(TransactionalDriver.password, password);
          return ConnectionManager.create(null, properties);
      }
  </code></pre>
  
  <p>From my understanding this class was needed for transaction management. But This is the first time I have ever needed to use this dependency.</p>
  
  <p>I setup my datasource in my <code>application.properties</code> like so:</p>
  
  <pre><code>#Oracle database setup
  spring.datasource.url=jdbc:oracle:thin:@999.999.999.999:1521:d9rty
  spring.datasource.username=username
  spring.datasource.password=password
  spring.datasource.driver-class-name=oracle.jdbc.OracleDriver
  spring.profiles.active=oracle
  
  #JPA setup
  spring.jpa.hibernate.ddl-auto=validate
  spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
  
  spring.datasource.max-active=5
  
  server.port = 4000
  </code></pre>
  
  <p>Any advice would be greatly appreciated. </p>