[英]Spring Dependency for ResponseEntityExceptionHandler
I am not be able to import correctly ResponseEntityExceptionHandler我无法正确导入ResponseEntityExceptionHandler
class ControllerAdvice @Autowired()() extends ResponseEntityExceptionHandler{
What I am missing in my pom xml file?我的 pom xml 文件中缺少什么?
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/>
</parent>
try Add it inside dependency instead of the parent.尝试将其添加到依赖项而不是父项中。 parent is a base pom of your project.
parent 是您项目的基础 pom。
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
</dependencies>
You have added the dependency of spring-boot-starter-parent
which does not contain spring-web
dependency.您添加了
spring-boot-starter-parent
的依赖项,它不包含spring-web
依赖项。 ResponseEntityExceptionHandler
class comes from spring-web
. ResponseEntityExceptionHandler
class 来自spring-web
。 So, you can add below dependency to the pom:因此,您可以向 pom 添加以下依赖项:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
or you can use spring-boot-starter-web
artifact which includes spring-web
by default.或者您可以使用默认包含
spring-web
的spring-boot-starter-web
工件。
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.1.9.RELEASE</version>
</dependency>
For more info you can look at pom of spring-boot-starter-web and spring-boot-starter-parent you see the dependencies that those artifact includes.有关更多信息,您可以查看spring-boot-starter-web和spring-boot-starter-parent的 pom,您会看到这些工件包含的依赖项。
Hi try to add this dependency您好尝试添加此依赖项
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.