Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
6635b6aa
Commit
6635b6aa
authored
Oct 03, 2017
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.5.x'
parents
bd02edf2
7e08e47b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
24 deletions
+18
-24
howto.adoc
spring-boot-docs/src/main/asciidoc/howto.adoc
+18
-24
No files found.
spring-boot-docs/src/main/asciidoc/howto.adoc
View file @
6635b6aa
...
...
@@ -1912,30 +1912,24 @@ is a Hibernate feature (nothing to do with Spring).
[[howto-initialize-a-database-using-spring-jdbc]]
=== Initialize a database using Spring JDBC
Spring JDBC has a `DataSource` initializer feature. Spring Boot enables it by default and
loads SQL from the standard locations `schema.sql` and `data.sql` (in the root of the
classpath). In addition Spring Boot will load the `schema-${platform}.sql`
and `data-${platform}.sql` files (if present), where
`platform` is the value of `spring.datasource.platform`, e.g. you might choose to set
it to the vendor name of the database (`hsqldb`, `h2`, `oracle`, `mysql`,
`postgresql` etc.). Spring Boot enables the fail-fast feature of the Spring JDBC
initializer by default, so if the scripts cause exceptions the application will fail
to start. The script locations can be changed by setting `spring.datasource.schema` and
`spring.datasource.data`, and neither location will be processed if
`spring.datasource.initialize=false`.
To disable the fail-fast you can set `spring.datasource.continue-on-error=true`. This can be
useful once an application has matured and been deployed a few times, since the scripts
can act as '`poor man's migrations`' -- inserts that fail mean that the data is already
there, so there would be no need to prevent the application from running, for instance.
If you want to use the `schema.sql` initialization in a JPA app (with
Hibernate) then `ddl-auto=create-drop` will lead to errors if
Hibernate tries to create the same tables. To avoid those errors set
`ddl-auto` explicitly to "" (preferable) or "none". Whether or not you use
`ddl-auto=create-drop` you can always use `data.sql` to initialize new
data.
=== Initialize a database
Spring Boot can automatically create the schema (DDL scripts) of your `DataSource` and
initialize it (DML scripts): it loads SQL from the standard root classpath locations
`schema.sql` and `data.sql`, respectively. In addition Spring Boot will process the
`schema-${platform}.sql` and `data-${platform}.sql` files (if present), where `platform`
is the value of `spring.datasource.platform`. This allows you to switch to database
specific scripts if necessary, e.g. you might choose to set it to the vendor name of the
database (`hsqldb`, `h2`, `oracle`, `mysql`, `postgresql` etc.).
Spring Boot enables the fail-fast feature of the Spring JDBC initializer by default, so if
the scripts cause exceptions the application will fail to start. You can tune that using
`spring.datasource.continue-on-error`.
NOTE: In a JPA-based app, you can choose to let Hibernate create the schema or use
`schema.sql` but not both. Make sure to disable `spring.jpa.hibernate.ddl-auto` if you
chose the later.
You can also disable initialization by setting `spring.datasource.initialize` to `false`.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment