Marcel
Marcel

Reputation: 101

Spring Boot : Cannot load driver class: org.hsqldb.jdbcDriver

I have a simple Spring Boot application (generated through Spring Roo).

The database is configured as following :

spring.datasource.driver-class-name=org.hsqldb.jdbcDriver
spring.datasource.url=jdbc\:hsqldb\:mem\:PetClinic
spring.jpa.hibernate.naming.strategy=org.hibernate.cfg.ImprovedNamingStrategy
spring.messages.encoding=ISO-8859-1
spring.messages.fallback-to-system-locale=false
spring.thymeleaf.mode=html

Here are the how I declared the HSQLDB dependency :

<dependency>
  <groupId>org.hsqldb</groupId>
  <artifactId>hsqldb</artifactId>
  <scope>provided</scope>
</dependency>

When I start the application, I get the error :

Caused by: java.lang.IllegalStateException: Cannot load driver class: org.hsqldb.jdbcDriver
    at org.springframework.util.Assert.state(Assert.java:392) ~[spring-core-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.boot.autoconfigure.jdbc.DataSourceProperties.determineDriverClassName(DataSourceProperties.java:214) ~[spring-boot-autoconfigure-1.4.1.RELEASE.jar:1.4.1.RELEASE]

The Spring-boot-autoconfigure module tries to load the class with the ClassUtils utility class that loads the current context classes.

I wonder if this method works fine since I use a Tomcat container which is responsible to load the Maven dependencies ? Why even with the JAR in the libs directory Spring is not able to find it ?

Upvotes: 10

Views: 16451

Answers (3)

lord5et
lord5et

Reputation: 500

Try following dependency config in your pom.xml (change your version number accordingly or remove it)

<dependency>
   <groupId>org.hsqldb</groupId>
   <artifactId>hsqldb</artifactId>
   <classifier>jdk8</classifier>
   <version>2.6.1</version>        
</dependency>

For me adding that classifier line solved an issue. Please see below recommendation in hsqldb repo. https://sourceforge.net/p/hsqldb/bugs/1644/

Upvotes: 1

Strelok
Strelok

Reputation: 51421

  1. Remove <scope>provided</scope> from your pom.xml
  2. Remove both spring.datasource.driver-class-name and spring.datasource.url properties from your application properties

Because:

  • when spring.datasource.url is provided the driver class name is redundant as Spring Boot will automatically attempt to load the correct driver.
  • since you want to use an embedded database you don't need to provide spring.datasource.url at all. Just need to have an embedded database JAR on the classpath (like HSQLDB)

Relevant docs snippet:

Spring Boot can auto-configure embedded H2, HSQL and Derby databases. You don’t need to provide any connection URLs, simply include a build dependency to the embedded database that you want to use.

Please read the Working with SQL databases section in of Spring Boot documentation. Everything I said is mentioned there, so you can get more detail.

Upvotes: 9

Anil Kumar Athuluri
Anil Kumar Athuluri

Reputation: 653

I see the scope you gave is provided, <scope>provided</scope>, I don't think Tomcat provides the hsqldb.jar with it out of the box.

So try removing the provided scope.

Upvotes: 6

Related Questions