resource/db/data.sql 만들기
매번 데이터를 넣기 힘드니까, 서버가 실행되면 h2데이터베이스를 값이 들어간 상태로 초기할 수 있다.
insert into user_tb(username, password, email, created_at) values('ssar', '1234', 'ssar@nate.com', now());
insert into user_tb(username, password, email, created_at) values('cos', '1234', 'cos@nate.com', now());
insert into user_tb(username, password, email, created_at) values('love', '1234', 'love@nate.com', now());
SQL
복사
application.yml 설정
server:
servlet:
encoding:
charset: utf-8
force: true
session:
timeout: 30m
port: 8080
spring:
mustache:
servlet:
expose-session-attributes: true
expose-request-attributes: true
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:test;MODE=MySQL
username: sa
password:
h2:
console:
enabled: true
sql:
init:
data-locations:
- classpath:db/data.sql
jpa:
hibernate:
ddl-auto: create
show-sql: true
properties:
hibernate:
format_sql: true
defer-datasource-initialization: true
YAML
복사
defer-datasource-initialization: true
ddl-auto가 된 후에 실행되게 하는 설정
YAML
복사
sql:
init:
data-locations:
- classpath:db/data.sql
스프링 실행할때 초기화하는 설정법
YAML
복사
테스트
//접속주소
http://localhost:8080/h2-console
Java
복사
Error creating bean with name 'dataSourceScriptDatabaseInitializer에러 해결
펼쳐보기
테스트 확인, 정상 작동하고 있다.
•
고객이 보내는 데이터
•
화면에 필요한 데이터