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

Spring Boot从1.5.3升级到2.1.3时依赖无法解析求助

解决Spring Boot 1.5.3升级到2.1.3后的依赖与导入问题

你遇到的这两个问题都是Spring Boot版本升级中典型的兼容性变更,我帮你逐个拆解并给出具体解决方案:

1. org.apache.tomcat.jdbc.pool.DataSource无法解析的问题

在Spring Boot 2.x版本里,默认数据源已经从Tomcat JDBC Pool切换为HikariCP,而且你的pom.xml里还在spring-boot-starter-data-jpa依赖中主动排除了tomcat-jdbc:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-jdbc</artifactId>
        </exclusion>
    </exclusions>
</dependency>

两种解决方式任你选:

  • 方案A:改用默认的HikariCP
    直接把代码里的org.apache.tomcat.jdbc.pool.DataSource替换为com.zaxxer.hikari.HikariDataSource,无需额外修改依赖,Spring Boot会自动完成配置。
  • 方案B:继续使用Tomcat JDBC Pool
    如果必须保留原数据源,先移除spring-boot-starter-data-jpa中的排除项,再添加明确的依赖:
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-jdbc</artifactId>
    </dependency>
    

2. import org.springframework.boot.web.support无法解析的问题

Spring Boot 2.x已经完全废弃了org.springframework.boot.web.support包,其中的核心类(比如SpringBootServletInitializer)都迁移到了org.springframework.boot.web.servlet.support包下。

解决办法:

直接修改代码里的导入语句,将:

import org.springframework.boot.web.support.SpringBootServletInitializer;

替换为:

import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

额外优化建议

  1. 做完依赖调整后,执行mvn clean install -U命令,强制清理Maven缓存并重新构建项目,确保依赖完全更新
  2. 检查项目中其他1.5.x版本的特有API,比如@WebMvcConfigurerAdapter也已被废弃,需要改为实现WebMvcConfigurer接口

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 09:04:38