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

引入neo4j-spatial依赖失败导致Maven构建失败求助

解决Spring Boot引入neo4j-spatial的依赖构建失败问题

嘿,我正好碰到过类似的问题,你的构建失败本质上是两个核心问题:指定版本的neo4j-spatial不在Maven中央仓库,以及Spring Boot、Neo4j和neo4j-spatial的版本兼容性匹配。下面一步步帮你解决:

1. 错误原因解析

你遇到的报错:

[ERROR] Failed to execute goal on project Neo4j: Could not resolve dependencies for project com.neo:Neo4j:jar:0.0.1-SNAPSHOT: Failure to find org.neo4j:neo4j-spatial:jar:0.25.5-neo4j-3.4.0 in https://repo.maven.apache.org/maven2 was cached in the local repository...

这是因为0.25.5-neo4j-3.4.0这个版本的neo4j-spatial并没有发布到Maven中央仓库,而是托管在Neo4j官方自己的Maven仓库里。另外,你使用的Spring Boot 2.0.2.RELEASE默认适配Neo4j 3.4.x系列,这个版本选择是没问题的,但需要让Maven能找到对应的依赖源。

2. 解决方案步骤

步骤一:添加Neo4j官方Maven仓库

在你的pom.xml中添加Neo4j的官方仓库,这样Maven就能从这里拉取neo4j-spatial的依赖:

<repositories>
    <repository>
        <id>neo4j-releases</id>
        <name>Neo4j Releases Repository</name>
        <url>https://m2.neo4j.com/content/repositories/releases/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

步骤二:确认版本兼容性(可选但推荐)

Spring Boot 2.0.2.RELEASE对应的Spring Data Neo4j版本是5.0.7.RELEASE,完美适配Neo4j 3.4.x,所以你选择的0.25.5-neo4j-3.4.0是匹配的。如果之后想升级,这里给个版本对应参考:

  • Spring Boot 2.0.x → Neo4j 3.4.x → neo4j-spatial 0.25.x-neo4j-3.4.x
  • Spring Boot 2.1.x → Neo4j 3.5.x → neo4j-spatial 0.26.x-neo4j-3.5.x

步骤三:强制刷新依赖缓存

如果之前Maven已经缓存了“找不到依赖”的结果,执行以下命令强制更新:

mvn clean install -U

3. 修改后的完整pom.xml示例

这里是整合了仓库配置后的完整pom.xml,你可以直接参考:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.neo</groupId>
<artifactId>Neo4j</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Neo4j</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>

<!-- 添加Neo4j官方仓库 -->
<repositories>
    <repository>
        <id>neo4j-releases</id>
        <name>Neo4j Releases Repository</name>
        <url>https://m2.neo4j.com/content/repositories/releases/</url>
        <releases>
            <enabled>true</enabled>
        </releases>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-spatial</artifactId>
<version>0.25.5-neo4j-3.4.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.28 07:22:17