gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 06:18:09 27 4
gpt4 key购买 nike

我正在使用以下指令开发 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
<小时/>

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

如果有人能帮助我那就太好了,谢谢^^

__________________________更新_______________________

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

<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

最佳答案

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

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

关于java - org.springframework.web.bind.annotation.ResponseStatus 和 org.springframework.http.HttpStatus 不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55852769/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com