db/sql
인텔리제이에서 H2 database 연결
kirinman
2022. 12. 23. 23:54
1. build.gradle에 다음과 같이 설정한다.
(spring boot 프로젝트 생성할 때 dependencies 추가한 내용과 겹칠 수 있음)
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
compileOnly 'org.projectlombok:lombok'
developmentOnly 'org.springframework.boot:spring-boot-devtools'
runtimeOnly 'com.h2database:h2'
annotationProcessor 'org.projectlombok:lombok'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
2.h2 데이터베이스 설정
src의 resources폴더의 application.properties 에 다음과 같이 설정해준다.
// h2 데이터베이스 기본 접속 주소 (In-Memory일 경우)
spring.datasource.url=jdbc:h2:mem:testdb;
// h2 드라이버
spring.datasource.driverClassName=org.h2.Driver
// h2 데이터베이스 접속 username
spring.datasource.username=sa
// h2 데이터베이스 접속 password
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
// jpa 사용 시, DDL 적용 모드
spring.jpa.hibernate.ddl-auto=create
// h2-console 활성화
spring.h2.console.enabled=true
// h2-console의 url 지정
spring.h2.console.path=/h2-console
근데 밑에처럼 네 줄만 써서 해도 되더라
설정 이후 어플리케이션을 실행시키고 http://localhost:8080/h2-console 에 접속하면 h2 웹 콘솔을 이용할 수 있다!