【问题标题】:can't use @Entity annotation in spring boot, gradle project不能在spring boot,gradle项目中使用@Entity注解
【发布时间】:2021-07-16 06:35:08
【问题描述】:

这是我的build.gradle 文件依赖项,

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-web'
   testImplementation('org.springframework.boot:spring-boot-starter-test') {
      exclude group: 'org.junit.vintage', module: 'junit-vintage-engine'
   }
   implementation group: 'javax.persistence', name: 'javax.persistence-api', version: '2.2'
   compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
   compile group: 'org.springframework.boot', name: 'spring-boot-starter-mail', version: '2.4.1'
   implementation group: 'javax.validation', name: 'validation-api', version: '2.0.1.Final'

}

我为学生创建了模型类。但我不能使用 @Entity 注释它标记为编译错误。如何使用 gradle 创建实体?

【问题讨论】:

  • 你必须在你的build.gradle中包含这个:implementation 'org.springframework.boot:spring-boot-starter-data-jpa'建议你使用start.spring.io来生成spring boot项目。你的 gradle 文件看起来很奇怪。

标签: java spring-boot jpa gradle spring-data-jpa


【解决方案1】:

@Entity 注解是从 javax.persistence.* 导入的

确保您有以下内容

// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa

implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '2.4.5'

【讨论】:

    猜你喜欢
    • 2023-03-19
    • 2014-11-11
    • 1970-01-01
    • 2018-09-29
    • 2020-04-13
    • 2017-09-02
    • 1970-01-01
    • 2019-03-02
    • 2020-01-16
    相关资源
    最近更新 更多