简体   繁体   中英

Spring Dependency for ResponseEntityExceptionHandler

I am not be able to import correctly ResponseEntityExceptionHandler

class ControllerAdvice @Autowired()() extends ResponseEntityExceptionHandler{

What I am missing in my pom xml file?

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

<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. ResponseEntityExceptionHandler class comes from spring-web . So, you can add below dependency to the 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.

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

Hi try to add this dependency

  <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM