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

Spring Boot 3.0.0升级后Rest Endpoint无法正常工作求助

Spring Boot 3.0.0升级后Rest端点404排查方案

1. 修复Servlet容器兼容性问题

你当前使用的tomcat7-maven-plugin(对应Tomcat 7)与Spring Boot 3.x完全不兼容:

  • Spring Boot 3.x基于Jakarta EE 9+规范,要求Servlet 5.0及以上版本,而Tomcat 7仅支持Servlet 3.0,且未适配Jakarta命名空间
  • 解决方式:
    • 移除tomcat7-maven-plugin,直接执行mvn spring-boot:run启动应用(Spring Boot自带的嵌入式Tomcat 10.x符合要求)
    • 若需部署到外部容器,改用Tomcat 10.x或更高版本,对应的Maven插件可替换为org.apache.tomcat.maven:tomcat10-maven-plugin

2. 确认War包启动类配置

War包部署场景下,Spring Boot启动类必须继承SpringBootServletInitializer并实现configure方法,确保应用上下文正确初始化:

@SpringBootApplication
public class ApplicationDataApplication extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(ApplicationDataApplication.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(ApplicationDataApplication.class, args);
    }
}

同时确保启动类所在包能覆盖TestResource的包路径,若控制器在启动类的包层级外,需手动指定扫描范围:

@SpringBootApplication(scanBasePackages = "de.app")

3. 验证请求路径正确性

根据你的Tomcat插件配置,应用上下文路径为/applicationdata-database,因此正确的请求地址应为:
http://localhost:8080/applicationdata-database/test/test
若省略上下文路径直接访问/test/test,必然返回404。

4. 启用调试日志排查映射问题

在application.properties中添加日志配置,查看请求处理细节:

logging.level.org.springframework.web=DEBUG
logging.level.org.springframework.context.annotation=DEBUG

启动后观察控制台,若RequestMappingHandlerMapping输出的映射列表中包含/test/test,说明控制器已被正常扫描;若未出现该映射,需重点检查组件扫描配置或控制器类的注解是否正确。

5. 补充Jakarta EE依赖完整性

Spring Boot 3.x已完全迁移到Jakarta命名空间,你已添加jakarta.xml.bind-api,但还需补充JAXB实现依赖(避免因序列化组件缺失导致的隐式加载异常):

<dependency>
    <groupId>org.glassfish.jaxb</groupId>
    <artifactId>jaxb-runtime</artifactId>
</dependency>

内容的提问来源于stack exchange,提问作者phe

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 08:30:46