title: Failed to load driver class org.mariadb.jdbc.Driver
body: <p>I want to configure 2 JNDI datasources in Spring Boot. I tried this configuration:</p>
  
  <p><strong><em>application.properties</em></strong></p>
  
  <pre><code>spring.production-datasource.jndi-name=java:/global/production_gateway
  spring.production-datasource.driver-class-name=org.mariadb.jdbc.Driver
  spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialect
  spring.jpa.show-sql = true
  spring.jpa.hibernate.ddl-auto = update
  
  spring.warehouse-datasource.jndi-name=java:/global/production_warehouse
  spring.warehouse-datasource.driver-class-name=org.mariadb.jdbc.Driver
  spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialect
  spring.jpa.show-sql = true
  spring.jpa.hibernate.ddl-auto = update
  </code></pre>
  
  <p>Primary datasource configuration:</p>
  
  <pre><code>    @Configuration
  @EnableJpaRepositories(
          basePackages = "org.datalis.plugin.production.entity", 
          entityManagerFactoryRef = "productionEntityManager", 
          transactionManagerRef = "productionTransactionManager"
      )
  @EnableTransactionManagement
  public class ContextProductionDatasource {
  
      @Autowired
      private Environment env;
  
      @Primary
      @Bean(name = "productionDataSourceProperties")
      @ConfigurationProperties(prefix="spring.production.datasource")
      public DataSourceProperties productionDataSourceProperties() {
          return new DataSourceProperties();
      }   
  
      @Primary
      @Bean(name = "productionDataSource")
      @ConfigurationProperties(prefix="spring.production.datasource")
      public DataSource productionDataSource() {
          return DataSourceBuilder.create().build();
      }
  
      @Primary
      @Bean(name = "productionEntityManager") 
      public EntityManager productionEntityManager(EntityManagerFactory emf) {
          return emf.createEntityManager();
      }
  
      @Primary
      @Bean(name = "productionTransactionManager")    
      public PlatformTransactionManager productionTransactionManager(final EntityManagerFactory emf) {
          final JpaTransactionManager transactionManager = new JpaTransactionManager();
          transactionManager.setEntityManagerFactory(emf);
          return transactionManager;
      }
  
      @Primary
      @Bean(name = "productionExceptionTranslation")
      public PersistenceExceptionTranslationPostProcessor productionExceptionTranslation() {
          return new PersistenceExceptionTranslationPostProcessor();
      }
  }
  </code></pre>
  
  <p>Second datasource configuration:</p>
  
  <pre><code>    @Configuration
  @EnableJpaRepositories(
          basePackages = "org.datalis.plugin.warehouse.entity", 
          entityManagerFactoryRef = "warehouseEntityManager", 
          transactionManagerRef = "warehouseTransactionManager"
      )
  @EnableTransactionManagement
  public class ContextWarehouseDatasource {
  
      @Autowired
      private Environment env;
  
      @Bean(name = "warehouseDataSourceProperties")
      @ConfigurationProperties(prefix="spring.warehouse.datasource")
      public DataSourceProperties warehouseDataSourceProperties() {
          return new DataSourceProperties();
      }
  
      @Bean(name = "warehouseDataSource")
      @ConfigurationProperties(prefix="spring.warehouse.datasource")
      public DataSource warehouseDataSource() {
          return DataSourceBuilder.create().build();
      }
  
      @Bean(name = "warehouseEntityManager")  
      public EntityManager warehouseEntityManager(EntityManagerFactory emf) {
          return emf.createEntityManager();
      }
  
      @Bean(name = "warehouseTransactionManager")
      public PlatformTransactionManager warehouseTransactionManager(final EntityManagerFactory emf) {
          final JpaTransactionManager transactionManager = new JpaTransactionManager();
          transactionManager.setEntityManagerFactory(emf);
          return transactionManager;
      }
  
      @Bean(name = "warehouseExceptionTranslation")
      public PersistenceExceptionTranslationPostProcessor warehouseExceptionTranslation() {
          return new PersistenceExceptionTranslationPostProcessor();
      }
  }
  </code></pre>
  
  <p>But I get error during deployment:</p>
  
  <pre><code>    Caused by: java.lang.IllegalStateException: Unable to set value for property driver-class-name
          at deployment.datalis_rest_api.war//org.springframework.boot.context.properties.bind.JavaBeanBinder$BeanProperty.setValue(JavaBeanBinder.java:349)
          at deployment.datalis_rest_api.war//org.springframework.boot.context.properties.bind.JavaBeanBinder.bind(JavaBeanBinder.java:96)
          at deployment.datalis_rest_api.war//org.springframework.boot.context.properties.bind.JavaBeanBinder.bind(JavaBeanBinder.java:79)
          at deployment.datalis_rest_api.war//org.springframework.boot.context.properties.bind.JavaBeanBinder.bind(JavaBeanBinder.java:56)
          at deployment.datalis_rest_api.war//org.springframework.boot.context.properties.bind.Binder.lambda$bindDataObject$5(Binder.java:452)
          at deployment.datalis_rest_api.war//org.springframework.boot.context.properties.bind.Binder$Context.withIncreasedDepth(Binder.java:570)
          at deployment.datalis_rest_api.war//org.springframework.boot.context.properties.bind.Binder$Context.withDataObject(Binder.java:556)
          at deployment.datalis_rest_api.war//org.springframework.boot.context.properties.bind.Binder$Context.access$400(Binder.java:513)
          at deployment.datalis_rest_api.war//org.springframework.boot.context.properties.bind.Binder.bindDataObject(Binder.java:450)
          at deployment.datalis_rest_api.war//org.springframework.boot.context.properties.bind.Binder.bindObject(Binder.java:391)
          at deployment.datalis_rest_api.war//org.springframework.boot.context.properties.bind.Binder.bind(Binder.java:320)
          ... 132 more
  Caused by: java.lang.reflect.InvocationTargetException
          at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.base/java.lang.reflect.Method.invoke(Method.java:567)
          at deployment.datalis_rest_api.war//org.springframework.boot.context.properties.bind.JavaBeanBinder$BeanProperty.setValue(JavaBeanBinder.java:346)
          ... 142 more
  Caused by: java.lang.RuntimeException: Failed to load driver class org.mariadb.jdbc.Driver in either of HikariConfig class loader or Thread context classloader
          at deployment.datalis_rest_api.war//com.zaxxer.hikari.HikariConfig.setDriverClassName(HikariConfig.java:485)
  </code></pre>
  
  <p>I'm using Spring boot war deployed into Wildfly server with deployed mariadb-java-client-2.4.2.jar. It's working fine when I use single datasource configuration. But with second datasource I get exception. </p>
  
  <p>Do you know how I can fix this issue?</p>
  
  <p><strong><em>Second attempt</em></strong>:</p>
  
  <p><strong><em>application.properties:</em></strong></p>
  
  <pre><code>spring.production.datasource.jndi-name=java:/global/production_gateway
  spring.production.datasource.driver-class-name=org.mariadb.jdbc.Driver
  spring.production.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialect
  spring.production.jpa.show-sql = true
  spring.production.jpa.hibernate.ddl-auto = update
  
  spring.warehouse.datasource.jndi-name=java:/global/production_warehouse
  spring.warehouse.datasource.driver-class-name=org.mariadb.jdbc.Driver
  spring.warehouse.jpa.properties.hibernate.dialect=org.hibernate.dialect.MariaDBDialect
  spring.warehouse.jpa.show-sql = true
  spring.warehouse.jpa.hibernate.ddl-auto = update
  </code></pre>
  
  <p>First datasource:</p>
  
  <pre><code>@Configuration
  @EnableJpaRepositories(
          basePackages = "org.datalis.plugin.production.entity", 
          entityManagerFactoryRef = "productionEntityManager", 
          transactionManagerRef = "productionTransactionManager"
      )
  @EnableTransactionManagement
  public class ContextProductionDatasource {
  
      @Primary
      @Bean(name = "productionDataSourceProperties")
      @ConfigurationProperties(prefix="spring.production")
      public DataSourceProperties productionDataSourceProperties() {
          return new DataSourceProperties();
      }   
  
      @Primary
      @Bean(name = "productionDataSource")
      @ConfigurationProperties(prefix="spring.production")
      public DataSource productionDataSource() {
          return DataSourceBuilder.create().build();
      }
  
      @Primary
      @Bean(name = "productionEntityManager") 
      public EntityManager productionEntityManager(EntityManagerFactory emf) {
          return emf.createEntityManager();
      }
  
      @Primary
      @Bean(name = "productionTransactionManager")    
      public PlatformTransactionManager productionTransactionManager(final EntityManagerFactory emf) {
          final JpaTransactionManager transactionManager = new JpaTransactionManager();
          transactionManager.setEntityManagerFactory(emf);
          return transactionManager;
      }
  
      @Primary
      @Bean(name = "productionExceptionTranslation")
      public PersistenceExceptionTranslationPostProcessor productionExceptionTranslation() {
          return new PersistenceExceptionTranslationPostProcessor();
      }
  }
  </code></pre>
  
  <p>Second datasource:</p>
  
  <pre><code>@Configuration
  @EnableJpaRepositories(
          basePackages = "org.datalis.plugin.warehouse.entity", 
          entityManagerFactoryRef = "warehouseEntityManager", 
          transactionManagerRef = "warehouseTransactionManager"
      )
  @EnableTransactionManagement
  public class ContextWarehouseDatasource {
  
      @Bean(name = "warehouseDataSourceProperties")
      @ConfigurationProperties(prefix="spring.warehouse")
      public DataSourceProperties warehouseDataSourceProperties() {
          return new DataSourceProperties();
      }
  
      @Bean(name = "warehouseDataSource")
      @ConfigurationProperties(prefix="spring.warehouse")
      public DataSource warehouseDataSource() {
          return DataSourceBuilder.create().build();
      }
  
      @Bean(name = "warehouseEntityManager")  
      public EntityManager warehouseEntityManager(EntityManagerFactory emf) {
          return emf.createEntityManager();
      }
  
      @Bean(name = "warehouseTransactionManager")
      public PlatformTransactionManager warehouseTransactionManager(final EntityManagerFactory emf) {
          final JpaTransactionManager transactionManager = new JpaTransactionManager();
          transactionManager.setEntityManagerFactory(emf);
          return transactionManager;
      }
  
      @Bean(name = "warehouseExceptionTranslation")
      public PersistenceExceptionTranslationPostProcessor warehouseExceptionTranslation() {
          return new PersistenceExceptionTranslationPostProcessor();
      }
  }
  </code></pre>
  
  <p>Now I get:</p>
  
  <pre><code>Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean]: Factory method 'entityManagerFactory' threw exception; nested exception is java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required.
          at deployment.datalis_rest_api.war//org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
          at deployment.datalis_rest_api.war//org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:640)
          ... 41 more
  Caused by: java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required.
  </code></pre>