![](/img/trans.png)
[英]Get HttpServletRequest into Spring ResponseEntityExceptionHandler
[英]Spring Dependency for ResponseEntityExceptionHandler
我無法正確導入ResponseEntityExceptionHandler
class ControllerAdvice @Autowired()() extends ResponseEntityExceptionHandler{
我的 pom xml 文件中缺少什么?
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath/>
</parent>
嘗試將其添加到依賴項而不是父項中。 parent 是您項目的基礎 pom。
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
</dependency>
</dependencies>
您添加了spring-boot-starter-parent
的依賴項,它不包含spring-web
依賴項。 ResponseEntityExceptionHandler
class 來自spring-web
。 因此,您可以向 pom 添加以下依賴項:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</dependency>
或者您可以使用默認包含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>
有關更多信息,您可以查看spring-boot-starter-web和spring-boot-starter-parent的 pom,您會看到這些工件包含的依賴項。
您好嘗試添加此依賴項
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.