在Spring Boot应用程序中配置嵌入式Derby [英] Configuring embedded Derby in Spring Boot app
问题描述
您能帮我在Spring Boot应用程序中建立与嵌入式Derby数据库的连接吗?
Could you please help me set up connection to the embedded Derby database in Spring Boot application?
我在网上搜索,但只能找到服务器类型Derby的解决方案,而不适用于嵌入式Derby。
I searched the web but can only find solutions for server-type Derby, not for embedded Derby.
spring.jpa.database = ?
spring.jpa.hibernate.ddl-auto = create-drop
推荐答案
Derby作为内存数据库
如果您想使用Spring Boot配置内存 Derby数据库,则您需要做的最简单的事情就是提及运行时依赖项(以及 spring-boot-starter-data-jpa
)作为
Derby as an in-memory database
If you want to Configure in-memory Derby database with spring boot, the minimal thing you need is to mention the runtime dependency (along with spring-boot-starter-data-jpa
) as
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>runtime</scope>
</dependency>
这个最低限度的配置应该适用于Spring Boot中的任何嵌入式数据源。但是从当前的Spring Boot版本( 2.0.4.RELEASE )开始,这只会导致 Derby
This bare minimum configuration should work for any embedded datasource in Spring Boot. But as of current Spring Boot version (2.0.4.RELEASE) this lead to an error only for Derby
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing
DDL via JDBC Statement
Caused by: java.sql.SQLSyntaxErrorException: Schema 'SA' does not exist
这是由于 spring.jpa.hibernate的默认配置而发生的。 ddl-auto = create-drop
参见此春季启动问题。
This happens because of default configuration ofspring.jpa.hibernate.ddl-auto=create-drop
see this spring-boot issue for details.
因此,您需要在 application.properties
中将该属性覆盖为
So you need to override that property in your application.properties
as
spring.jpa.hibernate.ddl-auto=update
Derby作为持久性数据库</ h2>
如果要使用Derby作为持久性数据库。添加这些应用程序属性
Derby as a persistent database
If you want to use Derby as your persistent database. Add these application properties
spring.datasource.url=jdbc:derby:mydb;create=true
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.DerbyTenSevenDialect
spring.jpa.hibernate.ddl-auto=update
这篇关于在Spring Boot应用程序中配置嵌入式Derby的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!