Spring Boot non-embedded Derby database?

自作多情 提交于 2020-08-26 05:41:46

问题


How do I configure Spring Boot to connect to a network-based Derby database? I do not want an embedded Derby DB to be used, however it is constantly trying to load the EmbeddedDriver class.

java.sql.SQLException: Unable to load class: org.apache.derby.jdbc.EmbeddedDriver from ClassLoader:sun.misc.Launcher$AppClassLoader@4d6c3502;ClassLoader:sun.misc.Launcher$AppClassLoader@4d6c3502
    at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:280)

I have the following in my application.properties:

spring.datasource.url=jdbc:derby://localhost:1527/MyTestDb
spring.datasource.username=Eric
spring.datasource.password=eric
spring.datasource.initialize=false

And my pom has the following:

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derbyclient</artifactId>
        <version>10.11.1.1</version>
    </dependency>

My Application.java class is boilerplate:

@EnableAutoConfiguration
@Configuration
@ComponentScan
@EnableCaching
public class Application {

   public static void main(String[] args) {
        SpringApplication app = new SpringApplication(Application.class);
        app.setShowBanner(false);
       app.run(args);
    }
}

Is there some additional special config I have to do?


回答1:


As alluded to by @XtremeBiker, I was missing the driver class name in the application.properties file to force Spring to use the client driver and not the Embedded driver (by default)

spring.datasource.url=jdbc:derby://localhost:1527/MyTestDb
spring.datasource.username=Eric
spring.datasource.password=eric
spring.datasource.initialize=false
spring.datasource.driver-class-name=org.apache.derby.jdbc.ClientDriver


来源:https://stackoverflow.com/questions/32724434/spring-boot-non-embedded-derby-database

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!