首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >org.springframework.web.bind.annotation.ResponseStatus和org.springframework.http.HttpStatus不存在

org.springframework.web.bind.annotation.ResponseStatus和org.springframework.http.HttpStatus不存在
EN

Stack Overflow用户
提问于 2019-04-25 15:23:51
回答 1查看 1.7K关注 0票数 0

我正在开发一个CRUD Web应用程序,使用以下说明:

https://www.javaguides.net/2019/02/spring-boot-2-angular-7-crud-example-tutorial.html作为指南说,在编译文件: ResourceNotFoundException.java时,我使用了spring框架作为后端。

它给了我这个错误:

代码语言:javascript
运行
复制
C:\Users\Roberto\Desktop\ springboot2-jpa-crud-example\src\test\java\net\guides\springboot2\springboot2jpacrudexample\exception>javac ResourceNotFoundException.java
    ResourceNotFoundException.java:2: error: package org.springframework does not exist
    import org.springframework.http;

                          ^
ResourceNotFoundException.java:3: error: package org.springframework.http does not exist
import org.springframework.http.HttpStatus;
                               ^
ResourceNotFoundException.java:4: error: package org.springframework.web.bind does not exist
import org.springframework.web.bind.annotation;
                                   ^
ResourceNotFoundException.java:5: error: package org.springframework.web.bind.annotation does not exist
import org.springframework.web.bind.annotation.ResponseStatus;
                                              ^
ResourceNotFoundException.java:7: error: cannot find symbol
@ResponseStatus(value = HttpStatus.NOT_FOUND)
 ^
  symbol: class ResponseStatus
5 errors

我在web上注意到,这个问题可以由maven版本o npm版本(npm -version 6.9.0 \ mvn -v Apache Maven 3.6.1)来解决,并且可以通过向pom.xlm文件添加一些依赖项来解决问题,我在这里发布了pom.xlm文件:

">http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0

代码语言:javascript
运行
复制
<groupId>net.guides.springboot2</groupId>
<artifactId>springboot2-jpa-crud-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>springboot2-jpa-crud-example</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
</properties>

<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>org.springframework.boot</groupId>
       <artifactId>spring-boot-devtools</artifactId>
       <scope>runtime</scope>
   </dependency>
   <dependency>
       <groupId>mysql</groupId>
       <artifactId>mysql-connector-java</artifactId>
       <scope>runtime</scope>
   </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>

如果有人能帮我,那就太棒了

__________________________UPDATE_______________________

正如下面的评论所示,我只是尝试将此代码添加到我的pom.xlm文件中

代码语言:javascript
运行
复制
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.1.6.RELEASE</version>

但是在编译之后,它没有工作

代码语言:javascript
运行
复制
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /C:/Users/Roberto/Desktop/ springboot2-jpa-crud- 
example/src/test/java/net/guides/springboot2/springboot2jpacrudexample/
exception 
/ResourceNotFoundException.java:[6,8] duplicate class: 
com.companyname.springbootcrudrest.exception.ResourceNotFoundException
[ERROR] /C:/Users/Roberto/Desktop/ springboot2-jpa-crud- 
example/src/test/java/net/guides/springboot2
/springboot2jpacrudexample/controller 
/EmployeeController.java:[20,66] cannot access 
net.guides.springboot2.springboot2jpacrudexample.
exception.ResourceNotFoundException
bad source file: C:\Users\Roberto\Desktop\ springboot2-jpa-crud- 
example\src\test\java\net\guides\springboot2
\springboot2jpacrudexample\exception\ 
ResourceNotFoundException.java
file does not contain class 
net.guides.springboot2.springboot2jpacrudexample.
exception.ResourceNotFoundException
EN

回答 1

Stack Overflow用户

发布于 2019-04-25 15:28:18

请将此依赖项添加到POM.xml

代码语言:javascript
运行
复制
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>5.1.6.RELEASE</version>
</dependency>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55852769

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档