Home  >  Forum  >  Spring
Post New Query

Failed to load driver class org.h2.Driver



Asked on August 02, 2019
Hi, I am creating Spring Batch application using H2 database. I configured datasource using HikariCP in JavaConfig.

@Bean
public DataSource getDataSource() {
HikariDataSource dataSource = new HikariDataSource();
dataSource.setDriverClassName("org.h2.Driver");
dataSource.setJdbcUrl("jdbc:h2:~/test");
dataSource.setUsername("sa");
dataSource.setPassword("");
return dataSource;
}

But I am getting error. What is wrong?

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.sql.DataSource]: Circular reference involving containing bean 'appConfiguration' - consider declaring the factory method as static for independence from its containing instance. Factory method 'getDataSource' threw exception; nested exception is java.lang.RuntimeException: Failed to load driver class org.h2.Driver in either of HikariConfig class loader or Thread context classloader
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:622) ~[spring-beans-5.1.8.RELEASE.jar:5.1.8.RELEASE]
... 59 common frames omitted
Caused by: java.lang.RuntimeException: Failed to load driver class org.h2.Driver in either of HikariConfig class loader or Thread context classloader
at com.zaxxer.hikari.HikariConfig.setDriverClassName(HikariConfig.java:497) ~[HikariCP-3.2.0.jar:na]



Replied on August 02, 2019
Try by resolving H2 database dependency.

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>


Write Answer








©2019 concretepage.com | Privacy Policy | Contact Us