简体   繁体   中英

Spring Boot non-embedded Derby database?

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?

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

The below config works for me

application.properties

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.DerbyTenSevenDialect
spring.jpa.database-platform=org.hibernate.dialect.DerbyTenSevenDialect
    
spring.datasource.url=jdbc:derby://localhost:1527/MyDbTest
spring.datasource.driver-class-name=org.apache.derby.jdbc.ClientDriver
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl

pom.xml

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM