こちらのサイト(https://intellectual-curiosity.tokyo/2021/06/03/spring-boot%e3%81%a7%e3%83%87%e3%83%bc%e3%82%bf%e3%83%99%e3%83%bc%e3%82%b9%ef%bc%88postgresql%ef%bc%89%e3%81%ab%e3%82%a2%e3%82%af%e3%82%bb%e3%82%b9%e3%81%99%e3%82%8b%e6%96%b9%e6%b3%95gradle%e7%89%88/)を参考にSpringBootとGradleでPostgreSQLデータベースに接続しようとしています。
そこでbuild.gradleに設定を追加しmodelフォルダ配下にNews.javaクラスを作成したところ
The import javax.persistence cannot be resolved
のエラーが発生しました。
Newsクラスとbuild.gradleの内容は以下です。
原因が分からないため教えて下さい。
News
1package com.example.springapp.model; 2 3import java.sql.Timestamp; 4import javax.persistence.Entity; 5import javax.persistence.GeneratedValue; 6import javax.persistence.GenerationType; 7import javax.persistence.Id; 8import javax.persistence.Table; 9import lombok.Data; 10@Entity 11@Table(name="news") 12@Data 13public class News { 14 @Id 15 @GeneratedValue(strategy=GenerationType.IDENTITY) 16 private Integer id; 17 18 private String title; 19 20 private String summary; 21 22 private String url; 23}
build.gradle
1plugins { 2 id 'org.springframework.boot' version '2.7.4' 3 id 'io.spring.dependency-management' version '1.0.14.RELEASE' 4 id 'java' 5} 6 7group = 'com.example' 8version = '0.0.1-SNAPSHOT' 9sourceCompatibility = '17' 10 11configurations { 12 compileOnly { 13 extendsFrom annotationProcessor 14 } 15} 16 17repositories { 18 mavenCentral() 19} 20 21dependencies { 22 implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' 23 implementation 'org.springframework.boot:spring-boot-starter-web' 24 implementation 'org.springframework.boot:spring-boot-starter-data-jpa' 25 runtimeOnly 'org.postgresql:postgresql' 26 compileOnly 'org.projectlombok:lombok' 27 developmentOnly 'org.springframework.boot:spring-boot-devtools' 28 annotationProcessor 'org.projectlombok:lombok' 29 testImplementation 'org.springframework.boot:spring-boot-starter-test' 30} 31 32tasks.named('test') { 33 useJUnitPlatform() 34}
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。