I am getting the following error with tomcat:
09:06:18,168 WARNING [org.apache.tomcat.jdbc.pool.PooledConnection] (ServerService Thread Pool -- 6) Not loading a JDBC driver as driverClassName property is null.
09:06:18,170 SEVERE [org.apache.tomcat.jdbc.pool.ConnectionPool] (ServerService Thread Pool -- 6) Unable to create initial connections of pool.: java.sql.SQLException: The url cannot be null
I have ran this both in JBOSS and the embedded tomcat server and still got this error. I even took out the jar files from the war from and ran it from JBOSS and still got the same error.
I am able to create the EntityMangers but before they are created I get the above error. The program continues to run than complains about a class is not a managed type. However those @Entities
are being scanned.
I get the same error with JBOSS:
09:06:18,171 WARN [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator] (ServerService Thread Pool -- 6) HHH000342: Could not obtain connection to query metadata : The url cannot be null
09:06:18,183 INFO [org.hibernate.dialect.Dialect] (ServerService Thread Pool -- 6) HHH000400: Using dialect: org.hibernate.dialect.Oracle10gDialect
09:06:18,199 INFO [org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl] (ServerService Thread Pool -- 6) HHH000422: Disabling contextual LOB creation as connection was null
DataSources:
@Configuration
@PropertySource("classpath:application.yml")
public class MainDataSourceConfig {
/*******************************
* Datasource *
* *****************************/
@Bean
@Primary
@ConfigurationProperties(prefix = "spring.dataSource.Main")
public DataSource mainDataSource() {
return DataSourceBuilder.create().build();
}
/*******************************
* Transaction manager *
* *****************************/
@Bean
@Primary
DataSourceTransactionManager transactionManager(@Qualifier("mainDataSource") DataSource datasource) {
DataSourceTransactionManager txm = new DataSourceTransactionManager(datasource);
return txm;
}
@Bean
@Primary
public LocalContainerEntityManagerFactoryBean entityManagerFactory(@Qualifier("mainDataSource")DataSource dataSource) {
LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
entityManagerFactory.setPersistenceUnitName("mainEntityManger");
entityManagerFactory.setDataSource(dataSource);
entityManagerFactory.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
entityManagerFactory.setJpaDialect(new HibernateJpaDialect());
entityManagerFactory.setPackagesToScan("com.customers.domain");
entityManagerFactory.setJpaProperties(additionalProperties());
return entityManagerFactory;
}
private Properties additionalProperties() {
Properties properties = new Properties();
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
properties.setProperty("hibernate.ddl-auto","none");
return properties;
}
}
Second DataSource
@Configuration
@PropertySource("classpath:application.yml")
public class SecondDataSourceConfig {
/*******************************
* Datasource *
* *****************************/
@Bean
@ConfigurationProperties(prefix="spring.dataSource.Second")
public DataSource secondDataSource() {
return DataSourceBuilder.create().build();
}
/*******************************
* Transaction manager *
* *****************************/
@Bean
DataSourceTransactionManager transactionManager(@Qualifier("secondDataSource") DataSource datasource) {
DataSourceTransactionManager txm = new DataSourceTransactionManager(datasource);
return txm;
}
@Bean
public LocalContainerEntityManagerFactoryBean keyviewEntityMangerFactory(@Qualifier("secondDataSource") DataSource dataSource) {
LocalContainerEntityManagerFactoryBean entityManagerFactory = new LocalContainerEntityManagerFactoryBean();
entityManagerFactory.setPersistenceUnitName("secondEntityManger");
entityManagerFactory.setDataSource(dataSource);
entityManagerFactory.setJpaVendorAdapter(new HibernateJpaVendorAdapter());
entityManagerFactory.setJpaDialect(new HibernateJpaDialect());
entityManagerFactory.setPackagesToScan("com.statements.domain");
entityManagerFactory.setJpaProperties(additionalProperties());
return entityManagerFactory;
}
private Properties additionalProperties() {
Properties properties = new Properties();
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
properties.setProperty("hibernate.ddl-auto","none");
return properties;
}
}
application.yml
#Spring Boot Config for Oracle
spring:
dataSource:
Main:
url: [url]
username: [username]
password: [password]
driverClassName: oracle.jdbc.OracleDriver
Second:
url: [url]
username: [username]
password: [password]
driverClassName: oracle.jdbc.OracleDriver
tomcat:
min-idle: 1
# Spring Boot Actuator settings
#https://docs.spring.io/spring-boot/docs/current/reference/html/production-ready-endpoints.html
endpoints.health.sensitive: false
#management.security.enabled: true
management.context-path: /healthCheck
endpoints.info.id: info
endpoints.info.sensitive: false
endpoints.info.enabled: true
info.app.name: Request
info.app.description: Request Description
info.app.version: 0.0.1-SNAPSHO
I have been at this for over a week I cannot figure out why it is saying the url is null and later when the entityManagers are created saying one of my domain packages are not a managed type. It seems to have an issue scanning second set of packages. I confirmed this changing the class names since I noticed it was compiled it alphabetical order and when I did that it changed which package it was complaining about. #note: It picks a different class every time I run it of that same package and they are @Entity
annotated.
I am also using @EntityScan
, @ComponentScan
, @SpringBootApplication
, @EnableAutoConfiguration
on the main method.
NOTE: When I remove the second Datasource everything works fine. This only happens when I bring in the second one.
------------------------Update 1-----------------------------------
I just put the dataSource information into two different yml
files and still got the same error. Then I decided to take out the main data source out and just implement the second as the only one in the project. THEN I got the same error. However the URI and everything are correct, not sure why this is happening.