eclipse Spring Boot - javax 导入语句无法正常工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/37327697/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring Boot - javax Import statements not working correctly
提问by Brandon Hewlett
I just started working with Spring Boot, and am currently following this tutorialwith some small modifications to naming and using their own version of Eclipse
, which has this generatorbuilt in.
我刚开始使用Spring Boot,目前正在关注本教程,对命名和使用他们自己的版本进行了一些小的修改Eclipse
,其中内置了这个生成器。
When I get to the first snippet of code, I try just copying over the importstatements to start with,
当我到达第一个代码片段时,我尝试复制导入语句以开始,
import com.fasterxml.Hymanson.annotation.JsonIgnore;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import java.util.HashSet;
import java.util.Set;
which gets me the following error with the javax imports:
这让我在 javax 导入时出现以下错误:
The import javax.persistence.[insert name here] cannot be resolved
When I find the javax.persistence
package, I find that, sure enough, the starter code provided from their own service does not contain the listed packages. I'm left confused and wondering if I did something wrong in the initial steps. Anyone have any ideas?
当我找到这个javax.persistence
包时,我发现,果然,他们自己的服务提供的入门代码不包含列出的包。我很困惑,想知道我是否在最初的步骤中做错了什么。谁有想法?
Edit 1: pom content provided
编辑 1:提供 pom 内容
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.Me</groupId>
<artifactId>petstore</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>petstore</name>
<description>Petstore Project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
回答by Aman Tuladhar
Add spring-boot-starter-data-jpa
dependency
添加 spring-boot-starter-data-jpa
依赖
If you are using Maven
add to pom.xml
如果您使用Maven
添加到pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
If you are using Gradle
add in build.gradle
如果您Gradle
在build.gradle中使用add
compile "org.springframework.boot:spring-boot-starter-data-jpa"
for other refer this.
其他参考这个。
回答by Saad Ahmed
Add this dependency in you pom.xml
在 pom.xml 中添加此依赖项
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
After that Right click on your project and in maven option update your project. That should fix it.
之后右键单击您的项目并在 maven 选项中更新您的项目。那应该解决它。
回答by Harun ERGUL
In my case i have added below spring boot data dependency but still not be able to import javax.persistence.*
就我而言,我在 spring boot 数据依赖项下添加了以下内容,但仍然无法导入 javax.persistence.*
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
I realized that eclipse somehow not be able to adding this dependencies to my classpath. Firstly i tried right click on the project Maven>Update Project
but still not worked. Then I execute mvn eclipse:eclipse
inside the root directory and then after successful build i refreshed project in the eclipse. This time it worked.
我意识到 eclipse 以某种方式无法将此依赖项添加到我的类路径中。首先,我尝试右键单击该项目,Maven>Update Project
但仍然无效。然后我mvn eclipse:eclipse
在根目录中执行,然后在成功构建后我刷新了 eclipse 中的项目。这次成功了。