我正在将freemaker集成到我的intellij应用程序中。然而,每次我运行程序时,我都会遇到这个错误。
[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.bo
ot: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.s
pringframework.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>
我尝试了很多修复方法,比如无效并重新启动cachce,重新启动itellij和计算机等等。我甚至尝试了帮助这个用户Missing artifact org.springframework.boot:spring-boot-starter-parent:jar:1.3.2.RELEASE的修复程序,但它对我不起作用。
这是我的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>
如何解决此错误?
1条答案
按热度按时间osh3o9ms1#
您发布的错误显示:
https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-starter-freemarker/2.5.4/spring-boot-starter-freemarker-2.5.4.pom:无法访问网络:连接
这意味着您的
mvn
配置为使用中央Maven存储库,但无法从您的网络访问。这种访问可能会受到您所在组织的限制,在这种情况下,您通常应该配置一个代理来访问internet。代理是由IT部门提供给您的,它很可能已经在您的浏览器中自动配置。这是最流行的场景。例如,我在没有代理的情况下从我的家庭网络中访问中央Maven存储库中的依赖项没有任何问题(您也可以尝试这样做):此外,大多数时候,大公司都使用自己的“maven”存储库来镜像外部存储库,如中央回购。一些策略可能会应用于此镜像过程,但一般来说,像Spring Framework这样的著名工件都会被镜像。因此,如果存在内部回购url,您可能希望找到它。
在Maven中配置代理很容易。只需遵循https://maven.apache.org/guides/mini/guide-proxies.html的简短官方指南。您需要在
settings.xml
文件(通常为${user.home}/.m2/settings.xml)中添加(修改)代理部分。你也可以很容易地用谷歌搜索很多例子来做这件事。然后在IntelliJ中,确保“Preferences | Build,Execution,Deployment | Build Tools | Maven | User settings file”指向具有配置代理的
settings.xml
文件。