728x90
반응형
SpringBoot 에서 Jpa, H2 사용법 (application.yml, application.properties 둘 다 있음)
- application.properties 에 아래 설정해주기.
#DB
spring.datasource.url=jdbc:h2:file:./h2db/board
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username= 아이디
spring.datasource.password= 패스워드
#H2
spring.h2.console.path=/h2console
spring.h2.console.enabled=true
H2 console 화면 접속
- 위와 같이 h2.console 설정해주고 SpringBoot 를 실행시킨 후, localhost:8080/h2console 로 접속하면 h2 console 화면으로 접속 가능
- username, url 은 아래 application.yml 참조
build.gradle
plugins {
id 'org.springframework.boot' version '2.3.0.BUILD-SNAPSHOT'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'java'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '1.8'
configurations {
compileOnly {
extendsFrom annotationProcessor
}
}
repositories {
mavenCentral()
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-jdbc'
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
annotationProcessor 'org.projectlombok:lombok'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
}
implementation 'junit:junit:4.12'
}
test {
useJUnitPlatform()
}
application.yml 설정
spring:
datasource:
hikari:
jdbc-url: jdbc:h2:file:./h2db/sample
driver-class-name: org.h2.Driver
username: sa
maximum-pool-size: 5
minimum-idle: 1
pool-name: hikari
h2:
console:
path: /h2console
enabled: true
jpa:
hibernate:
ddl-auto: update
show-sql: true
properties:
hibernate:
format_sql: true
'Spring > boot' 카테고리의 다른 글
spring boot localDateTime parsing (0) | 2020.09.11 |
---|---|
spring-boot Controller Mock Testcase 작성 (0) | 2020.09.05 |
spring boot logback 파일 appender 특정 파일 로그 위치에 로그가 쌓이지 않는 현상 (0) | 2020.09.03 |
spring boot 에서 yml 파일을 읽어서 map object 를 만드는 것 (map 형태) (0) | 2020.07.10 |
[SpringBoot] AutoConfiguration 이란? (0) | 2020.07.10 |
댓글