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

问题描述 投票:0回答:1

我正在使用以下指令处理CRUD Web应用程序:

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

它让我回到了这个错误:

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

我注意到网络上的问题可能是由maven版本的opm版本(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

<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>

如果有人可以帮助我,这将是非常棒的thx ^^

__________________________UPDATE_______________________

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

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.1.6.RELEASE</version>


但在编译后它没有用

[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
java xml maven spring-boot dependencies
1个回答
0
投票

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

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>5.1.6.RELEASE</version>
</dependency>
© www.soinside.com 2019 - 2024. All rights reserved.