如何配置Spring Boot以连接到基于网络的Derby数据库?我不希望使用嵌入式Derby DB,但是它一直在尝试加载EmbeddedDriver类。
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)
我的application.properties中有以下内容:
spring.datasource.url=jdbc:derby://localhost:1527/MyTestDb
spring.datasource.username=Eric
spring.datasource.password=eric
spring.datasource.initialize=false
我的pom有以下内容:
<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>
我的Application.java类是样板文件:
@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);
}
}
我还需要做一些额外的特殊配置吗?
答案 0 :(得分:0)
正如@XtremeBiker所提到的那样,我在application.properties文件中缺少驱动程序类名,以强制Spring使用客户端驱动程序而不是嵌入式驱动程序(默认情况下)
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
答案 1 :(得分:0)
以下配置对我有用
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>