Reputation: 65
I have built a spring boot war file using maven, When I try to deploy the war file to an external tomcat server in command prompt. I get an exception.
Error creating bean with name 'inMemoryDatabaseShutdownExecutor' defined in class path resource [org/springframework/boot/devtools/autoconfigure/DevToolsDataSourceAutoConfiguration.class]: Unsatisfied dependency expressed through method 'inMemoryDatabaseShutdownExecutor' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [org/springframework/boot/autoconfigure/jdbc/DataSourceConfiguration$Hikari.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.zaxxer.hikari.HikariDataSource]: Factory method 'dataSource' threw exception; nested exception is java.lang.IllegalStateException: Cannot load driver class: oracle.jdbc.OracleDriver
I am using two application.properties files one in src/main/resources that has the actual datasource config to Oracle and another in src/test/resources that has a datasource for a H2 in memory database.
Please let me know if I missed anything, Like placing the property file in config under tomcat folder etc.
Upvotes: 0
Views: 932
Reputation: 11
I added the Datasource Configuration using the programmatic way as below and it worked, not sure why couldn't it be picked from application.properties.
@Configuration
public class DatasourceConfig {
@Bean
public DataSource datasource() {
return DataSourceBuilder.create()
.driverClassName("com.mysql.cj.jdbc.Driver")
.url("jdbc:mysql://localhost:3306/test_db")
.username("username")
.password("password")
.build();
}
}
Credits to Baeldung article here
Upvotes: 0
Reputation: 65
Okay, The root cause of this is there is no oracle6 jar in my war file - Even though I added the dependency in my pom.xml.
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>6</version>
<scope>system</scope>
<systemPath>${basedir}/lib/ojdbc6.jar</systemPath>
</dependency>
Therefore I've added the jar explicitly into my Tomcat lib and it worked.
Upvotes: 0
Reputation: 31
I suppose you have set oracle.jdbc.OracleDriver as driver-class-name on your application.properties under src/main/java, right? Did you remember to include this dependency on pom.xml similar to what follows?
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.4.0</version>
</dependency>
Edit
Try adding this to tomcat's context.xml:
<Resource name="jdbc/mydb" auth="Container" type="javax.sql.DataSource"
maxTotal="100" maxIdle="30" maxWaitMillis="10000"
username="xxx" password="xxx" driverClassName="oracle.jdbc.OracleDriver"
url="jdbc:oracle:thin:@localhost:1521:xe"/>
Upvotes: 0