GradleでJPAを準備する方法を紹介。
環境情報- OS Ubuntu 20.04 LTS \n \l
- Tomcat V9.0
- springframework.boot 2.2.4.RELEASE
対処方法
build.gradleの設定を以下にする。
dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' // JPA及びDB接続用 runtime 'org.postgresql:postgresql' implementation 'com.h2database:h2' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat' testImplementation('org.springframework.boot:spring-boot-starter-test') { exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' } }
続けてapplication.propertiesにDBの設定を行う。
# DB設定 spring.jpa.database=POSTGRESQL spring.datasource.url=jdbc:postgresql://localhost:5432/lodging spring.datasource.username=postgres spring.datasource.password=postgres
コメント