2

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>
michele
  • 26,348
  • 30
  • 111
  • 168

3 Answers3

0

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

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.

Amit Bera
  • 7,075
  • 1
  • 19
  • 42
  • Dependency added but the class is not found. – michele Oct 18 '19 at 10:58
  • Is your IDE saying that class not found? Or when you tried to build your project it's throwing the error? – Amit Bera Oct 18 '19 at 11:12
  • @michele I have just tired the 2nd option it is working fine for me. ResponseEntityExceptionHandler should be in `spring-webmvc-5.1.10.RELEASE-sources.jar`. Try the check if the mentioned jar is in the maven dependencies – Amit Bera Oct 18 '19 at 11:35
0

Hi try to add this dependency

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