我正在尝试创建一个基本的 Java Spring 程序。从哪里获取 javax.persistence?它无法解析持久性,并且尝试后无法在 Web 上查找 JAR。目前使用 IntelliJ 。
https://spring.io/guides/tutorials/rest/
package payroll;
import java.util.Objects;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
class Employee {
private @Id @GeneratedValue Long id;
private String name;
private String role;
最佳答案
该依赖项来自 spring-boot-starter-data-jpa
.
请查看教程中建议的依赖项(jpa、web、h2)。
如果您使用Gradle你应该有:
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-web'
runtimeOnly 'com.h2database:h2'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
或者Maven :
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
关于Java在IntelliJ中添加javax.persistence,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68296786/