You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SpringBoot 2.0.0.RELEASE中ErrorAttributes导入无法解析的编译问题

Fixing "Cannot resolve import for org.springframework.boot.autoconfigure.web.ErrorAttributes" in Spring Boot 2.0.0.RELEASE

Hey there, I’ve dealt with this exact snag when upgrading to Spring Boot 2.0—let’s walk through what’s causing it and how to fix it quickly.

1. The Root Cause: Package Restructuring

Spring Boot 2.0 completely refactored the web auto-configuration package structure to better separate Servlet and Reactive web stack concerns. The ErrorAttributes class you’re trying to import was moved out of the old org.springframework.boot.autoconfigure.web package.

Correct Import Statement

Depending on which web stack you’re using:

  • For Servlet-based applications (most standard Spring Boot web apps), update your import to:
    import org.springframework.boot.autoconfigure.web.servlet.error.ErrorAttributes;
    
  • For WebFlux (Reactive) applications, use this instead:
    import org.springframework.boot.autoconfigure.web.reactive.error.ErrorAttributes;
    

2. Verify Your Dependencies

Make sure you have the correct Spring Boot starter included in your build file—without it, the ErrorAttributes class won’t be available in your classpath.

Maven (pom.xml)

Ensure you’ve added the web starter:

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

Gradle (build.gradle)

Add the web starter dependency:

implementation 'org.springframework.boot:spring-boot-starter-web'

(For WebFlux, replace spring-boot-starter-web with spring-boot-starter-webflux)

3. Bonus: Check Custom Implementations

If you’ve created a custom class that implements or extends ErrorAttributes, double-check the method signatures. Spring Boot 2.0 added new default methods to the interface, so you might need to adjust your implementation to avoid compilation issues.

内容的提问来源于stack exchange,提问作者Salvador Borés

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 03:44:45