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 ?
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.
<scope>provided</scope>
from your pom.xml
spring.datasource.driver-class-name
and spring.datasource.url
properties from your application propertiesBecause:
spring.datasource.url
is provided the driver class name is redundant as Spring Boot will automatically attempt to load the correct driver.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With