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

集成Freemarker时spring-boot-starter-freemarker依赖无法解析求助

问题描述

在IntelliJ中集成Freemarker时,运行程序持续出现以下Maven依赖解析错误:

[ERROR] Failed to execute goal on project demo: Could not resolve dependencies for project com.example:demo:jar:0.0.1-SNAPSHOT: Failed to collect dependencies at org.springframework.boot:spring-boot-starter-freemarker:jar:2.5.4: Failed to read artifact descriptor for org.springframework.boot:spring-boot-starter-freemarker:jar:2.5.4: Could not transfer artifact org.springframework.boot:spring-boot-starter-freemarker:pom:2.5.4 from/to central (https://repo.maven.apache.org/maven2): transfer failed for https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-freemarker/2.5.4/spring-boot-starter-freemarker-2.5.4.pom: Network is unreachable: connect -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException

错误核心指向依赖:

<artifactId>spring-boot-starter-freemarker</artifactId>

已尝试清除缓存重启、重启IntelliJ及电脑,参考过相关依赖缺失问题的解决方案,但均无效。

项目的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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.4</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>11</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-freemarker</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>
解决方案

从错误信息判断,核心问题是Maven无法连接中央仓库下载依赖,以下是针对性解决步骤:

1. 排查网络问题

  • 尝试访问中央仓库中该依赖的pom文件地址,确认网络是否能正常访问Maven仓库资源。如果无法访问:
    • 切换网络环境(比如使用手机热点替代公司内网),排除网络限制。
    • 检查本地防火墙、代理设置,确认未拦截Maven的网络请求。

2. 配置国内Maven镜像

如果中央仓库访问不畅,替换为国内镜像源(如阿里云公共Maven镜像):

  • 找到本地Maven的settings.xml配置文件,路径通常为:
    • 用户目录下的.m2/settings.xml
    • Maven安装目录的conf/settings.xml
  • 在文件的<mirrors>标签内添加以下配置:
<mirror>
    <id>aliyunmaven</id>
    <mirrorOf>central</mirrorOf>
    <url>https://maven.aliyun.com/repository/public</url>
</mirror>
  • 保存配置后,在IntelliJ中执行Maven -> Clean -> Install重新构建项目。

3. 强制更新Maven依赖

  • 在IntelliJ右侧Maven面板,点击刷新按钮(🔄),勾选Force Update of Snapshots/Releases选项后执行更新。
  • 或在终端执行命令:
mvn clean install -U

4. 检查IntelliJ的Maven配置

  • 打开File -> Settings -> Build, Execution, Deployment -> Build Tools -> Maven:
    • 确认Maven home directory指向正确的本地Maven版本,而非内置Maven。
    • 确认User settings file指向修改过镜像配置的settings.xml文件。

5. 手动安装依赖(备选方案)

如果上述方法均无效,可手动下载依赖到本地仓库:

  • 找到对应版本的spring-boot-starter-freemarker的jar和pom文件。
  • 将文件放置到本地Maven仓库的对应路径:~/.m2/repository/org/springframework/boot/spring-boot-starter-freemarker/2.5.4/。
  • 回到IntelliJ重新构建项目。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 09:05:22