Spring-boot
2016-04-18 09:50:21 6 举报
AI智能生成
Spring-boot data source configuration
作者其他创作
大纲/内容
Spring-boot
Embedded Database support
auto-configure support
H2
HSQL
Derby
Simply include a build dependency
Example
\u00A0 \u00A0 org.springframework.boot\u00A0 \u00A0 spring-boot-starter-data-jpa\u00A0 \u00A0 org.hsqldb\u00A0 \u00A0 hsqldb\u00A0 \u00A0 runtime
Connection URLs
Not required
H2: DB_CLOSE_ON_EXIT=FALSE
In jHipster
jdbc:h2:file:./target/h2db/db/my-app;DB_CLOSE_DELAY=-1
HSQLDB: shutdown=true is NOT used
DBs
In-Memory
One connection per db
jdbc:h2:mem:
Opening two connections within the same JVM means opening two dbs.
Multiple connections per db
jdbc:h2:mem:db-name
Accessing the same database only works within the same VM and class loader
Access from another process
jdbc:h2:tcp://localhost/mem:db-name
Closing
adding ';DB_CLOSE_DELAY=-1' to the URL keeps the db alive as long as the JVM is alive.
File
URL: 'jdbc:h2:[file:][]'
'file:' is optional
adding ';DB_CLOSE_ON_EXIT=FALSE' to disable db closing on JVM exiting.
This is RECOMMENDED in spring-boot tutorials
Compatibility
compatibility modes
Integration test
an empty maven project
HSQLDB (server mode)
java -cp ../lib/hsqldb.jar org.hsqldb.server.Server --database.0 file:sandboxDb --dbname.0 sandboxDb
java -cp .;../lib/hsqldb.jar org.hsqldb.util.DatabaseManager \u00A0-user sa -url jdbc:hsqldb:database/sandboxDb
integrate with liquibase-maven-plugin
#liquibase.propertiesdriver: org.hsqldb.jdbc.JDBCDriverurl: jdbc:hsqldb:hsql://localhost/sandboxDbusername: SApassword:
org.hsqldb:hsqldb:2.2.8
org.liquibase:liquibase-core:2.0.5
org.liquibase:liquibase-maven-plugin:2.0.5
liquibase.properties
db.changelog.xml
database schema/data deployment
spring orm / hibernate / transactional annotation
test with in-memory db
Database
dependencies
spring-boot-starter-web
spring-boot-starter-validation
hibernate-validator
tomcat-embed-el
收藏
0 条评论
回复 删除
下一页