如何将Spring Boot v2.0.1项目降级至v1.3.1?降级后编译报错求助
Hey there, let's work through this Spring Boot downgrade issue together. The compile error you're hitting is directly tied to a package structure change between Spring Boot 2.0.1 and 1.3.1, plus a few other small adjustments you'll need to make. Here's the breakdown:
1. Fix the SpringBootServletInitializer Import
In Spring Boot 1.3.1, the SpringBootServletInitializer class lives in a completely different package than it does in 2.x. That org.springframework.boot.web.servlet.support package didn't exist back in 1.3.x—you'll need to update your import to:
import org.springframework.boot.context.web.SpringBootServletInitializer;
2. Verify Your ServletInitializer Implementation
While SpringApplicationBuilder exists in 1.3.1, some of its usage might differ slightly from what you had in 2.0.1. A standard, compatible implementation for 1.3.1 looks like this (note I also cleaned up your package name—usually you don't want a package ending with "Controller" since that's a class type, not a module):
package com.ui.usersetting; import org.springframework.boot.context.web.SpringBootServletInitializer; import org.springframework.boot.builder.SpringApplicationBuilder; import com.ui.usersetting.YourMainApplicationClass; // Replace with your actual main app class public class ServletInitializer extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { // This is the core method to wire your main app class return application.sources(YourMainApplicationClass.class); } }
3. Sync Your Gradle Configuration
Don't forget to make sure your Gradle setup is fully aligned with Spring Boot 1.3.1. Update your build script to use the correct plugin version, and ensure all dependencies are compatible (Spring Boot 1.3.1 pairs with Spring Framework 4.2.4.RELEASE):
buildscript { repositories { mavenCentral() } dependencies { classpath 'org.springframework.boot:spring-boot-gradle-plugin:1.3.1.RELEASE' } } apply plugin: 'spring-boot' // Rest of your dependencies should match 1.3.1's managed versions—avoid hardcoding versions that conflict
4. Watch for Other 2.x-Specific Code
If your project uses any other features introduced in Spring Boot 2.x (like default methods in WebMvcConfigurer, new annotations, or updated API endpoints), you'll need to refactor those to work with 1.3.1. For example:
- If you used
@GetMapping/@PostMapping, those exist in 1.3.1, but double-check any attribute values that might have changed. - Any WebFlux-related code won't work here—1.3.1 doesn't support reactive web stacks.
Once you make these adjustments, your project should compile successfully with Spring Boot 1.3.1.
内容的提问来源于stack exchange,提问作者Mark Lavin

