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

Spring Boot应用中Oracle ojdbc 19.17.0.0依赖解析失败求助

问题描述

我在Spring Boot应用中尝试使用Oracle客户端19.17.0.0,已在pom.xml中添加如下配置:

<properties>
    <oracle-database.version>19.17.0.0</oracle-database.version>
</properties>

<dependency>
    <groupId>com.oracle.database.jdbc</groupId>
    <artifactId>ojdbc8</artifactId>
    <version>${oracle-database.version}</version>
</dependency>

构建时发现项目依赖的spring-boot-dependencies-3.0.7.pom中,ojdbc-pom不存在19.17.0.0版本,仅提供19.18.0.0和19.16.0.0版本,导致构建失败并抛出依赖无法解析错误。想知道该如何解决?或者能否不引用spring-boot-dependencies-3.0.7.pom?

解决方案

方法1:覆盖Spring Boot依赖管理中的版本

Spring Boot的spring-boot-dependencies作为依赖管理父pom,会统一管控各类依赖版本,但你可以通过以下两种方式强制使用目标版本:

方式A:在dependencyManagement中声明版本

如果你的pom继承自spring-boot-starter-parent,可以在自身pom的dependencyManagement中添加Oracle JDBC的版本声明,直接覆盖父pom的配置:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>com.oracle.database.jdbc</groupId>
            <artifactId>ojdbc8</artifactId>
            <version>19.17.0.0</version>
        </dependency>
    </dependencies>
</dependencyManagement>

之后添加依赖时可省略版本号:

<dependencies>
    <dependency>
        <groupId>com.oracle.database.jdbc</groupId>
        <artifactId>ojdbc8</artifactId>
    </dependency>
</dependencies>

方式B:直接覆盖版本属性

Spring Boot用oracle-database.version属性管理Oracle依赖版本,你可以在自身pom的properties中重新定义该属性,强制覆盖父pom的默认值:

<properties>
    <oracle-database.version>19.17.0.0</oracle-database.version>
</properties>

这种方式下,原有的依赖配置无需修改,属性值会自动生效。

方法2:改用Spring Boot兼容的版本

如果没有强需求必须使用19.17.0.0,建议直接使用spring-boot-dependencies提供的19.16.0.0或19.18.0.0版本,既能避免版本冲突,也符合Spring Boot的依赖管理规范:

<properties>
    <oracle-database.version>19.18.0.0</oracle-database.version>
</properties>

方法3:不继承spring-boot-dependencies(不推荐)

可以选择不继承spring-boot-starter-parent(它间接引入了spring-boot-dependencies),但需要手动管理所有Spring Boot相关依赖的版本,维护成本极高且易出现版本兼容问题。若一定要这么做,可在dependencyManagement中导入spring-boot-dependencies并排除Oracle相关的依赖管理:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-dependencies</artifactId>
            <version>3.0.7</version>
            <type>pom</type>
            <scope>import</scope>
            <exclusions>
                <exclusion>
                    <groupId>com.oracle.database.jdbc</groupId>
                    <artifactId>ojdbc8</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>com.oracle.database</groupId>
                    <artifactId>ojdbc-pom</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>
</dependencyManagement>

之后再添加你的Oracle JDBC依赖即可,但这种方式会丢失Spring Boot统一版本管理的便利性,不建议使用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.18 11:27:23