Spring Boot DB related tips

Studying Spring Boot at "First Spring-Boot". I wrote a good thing about DB related settings, so I will introduce it.

Automatically loaded SQL file

In Spring Boot, if the following SQL file exists directly under the classpath (src / main / resources / *. sql), it will be read and executed.

schema-(platform).sql
schema.sql
data-(platform).sql
data.sql

When using Japanese for SQL files

src/main/resources/application.properties

spring.datasource.sql-script-encoding=UTF-8

H2 DB settings

src/main/resources/application.properties

spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE
spring.datasource.username=sa
spring.datasource.password=

If you want to make it persistent, change the url as follows

spring.datasource.url=jdbc:h2:file:./target/db/testdb

Settings for persistence spring.datasource.url=jdbc:h2:file:./target/db/testdb

Log4 SQL log output using JDBC

<dependency>
	<groupId>org.lazyluke</groupId>
	<artifactId>log4jdbc-remix</artifactId>
	<version>0.2.7</version>
</dependency>

--JDBC driver settings for Log4 JDBC

src/main/resources/application.properties

spring.datasource.driver-class-name=net.sf.log4jdbc.DriverSpy
spring.datasource.url=jdbc:log4jdbc:abridgement

--Log4 Log level setting for JDBC

src/main/resources/application.properties

logging.level.jdbc=OFF
logging.level.jdbc.sqltiming=DEBUG

reference

--First Spring-Boot https://www.amazon.co.jp/s/ref=a9_sc_1/357-5571034-7925567?rh=i%3Aaps%2Ck%3Aはじめてspring+boot&keywords=はじめてspring+boot&ie=UTF8&qid=1523177092

Recommended Posts

Spring Boot DB related tips
Spring Boot performance related settings
Spring Boot DB connection pool
Challenge Spring Boot
Spring Boot Form
Spring Boot Memorandum
gae + spring boot
SPRING BOOT learning record 01
Spring Boot + Heroku Postgres
Spring boot memo writing (1)
First Spring Boot (DI)
SPRING BOOT learning record 02
Spring Boot2 cheat sheet
Spring Boot exception handling
Spring boot development-development environment-
Spring Boot learning procedure
Learning Spring Boot [Beginning]
Spring boot memo writing (2)
Spring Boot 2.2 Document Summary
[Spring Boot] DataSourceProperties $ DataSourceBeanCreationException
Spring Boot 2.3 Application Availability
Spring boot tutorials Topics
Download with Spring Boot
[Spring Boot] Environment construction (macOS)
Set context-param in Spring Boot
Try Spring Boot from 0 to 100.
Generate barcode with Spring Boot
Hello World with Spring Boot
Implement GraphQL with Spring Boot
Spring Boot tutorial task schedule
Spring 5 & Spring Boot 2 Hands-on preparation procedure
Get started with Spring boot
Hello World with Spring Boot!
Spring Boot 2 multi-project in Gradle
[Spring Boot] Web application creation
spring boot port duplication problem
Spring Boot Hot Swapping settings
[Java] Thymeleaf Basic (Spring Boot)
Introduction to Spring Boot ① ~ DI ~
File upload with Spring Boot
Spring Boot starting with copy
Introduction to Spring Boot ② ~ AOP ~
Spring Boot starting with Docker
Java tips --Spring execution Summary
Hello World with Spring Boot
Set cookies with Spring Boot
[Spring Boot] Easy paging recipe
Use Spring JDBC with Spring Boot
Docker × Spring Boot environment construction
Major changes in Spring Boot 1.5
Add module with Spring Boot
Getting Started with Spring Boot
NoHttpResponseException in Spring Boot + WireMock
[Spring Boot] Send an email
Spring Boot application that specifies DB connection settings with parameters
Introduction to Spring Boot Part 1
Spring Boot External setting priority
Try using Spring Boot Security
[Java] [Spring] Spring Boot 1.4-> 1.2 Downgrade Note
Try Spring Boot on Mac
Create microservices with Spring Boot