基本的Spring Boot App无法在STS中构建

问题描述 投票:1回答:4

我正在尝试在STS中创建一个默认的spring boot应用程序。它在STS文件中创建了一个“spring starter project” - >。项目创建后未进行任何更改。错误立即显示在POM文件中...

它失败并出现以下错误。一切都是默认的,解决这个问题需要什么?

项目构建错误:com.example的不可解析的父POM:hello-boot:0.0.1-SNAPSHOT:无法从https://repo.maven.apache.org/maven2传输org.springframework.boot:spring-boot-starter-parent:pom:2.0.5.RELEASE缓存在本地存储库中,在中心的更新间隔过去或强制更新之前,不会重新尝试解析。原始错误:无法传输工件org.springframework.boot:spring-boot-starter-parent:pom:2.0.5.RELEASE from / to central(https://repo.maven.apache.org/maven2):repo.maven.apache.org和'parent.relativePath'points在没有当地的POM

pom文件如下:http://maven.apache.org/xsd/maven-4.0.0.xsd“> 4.0.0

<groupId>com.example</groupId>
<artifactId>first-boot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>first-boot</name>
<description>Hello Spring Boot in STS</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.5.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

<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-web</artifactId>
    </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>

spring-boot spring-tool-suite
4个回答
2
投票

按Alt + F5并从列表中选择您的项目,然后选中“强制更新快照/发布”复选框,然后单击确定。

现在右键单击项目并选择run - > maven build。


1
投票

第一步:右键单击项目文件夹> Maven>更新项目>确定

然后:右键单击项目文件夹> Run As> Maven build ...

  1. 选中“更新快照”
  2. 在“目标”字段中添加“干净安装”
  3. 点击“运行”

1
投票

这是您的互联网连接的问题。检查,是否可以使用浏览器访问http://repo.spring.io。如果是,请检查是否需要配置代理服务器。在大多数情况下,我们需要配置代理服务器。

我将帮助您完成在STS或eclipse中设置代理的步骤:

  1. here下载Apache Maven 3.5.4工具。
  2. 假设您下载了zip文件,现在解压缩它。
  3. 解压后,在里面导航:./Apache-maven-3.3.9/conf。现在在conf文件夹里面用任何文本编辑器打开setting.xml
  4. 现在在settings.xml文件中,查找代理标记并将其替换为此。
    <proxies>
     <proxy>
       <id>example-proxy</id>
      <active>true</active>
      <protocol>http</protocol>
      <host>proxy.example.com</host>
      <port>8080</port>
      <username>proxyuser</username>
      <password>somepassword</password>
      <nonProxyHosts>www.google.com|*.example.com</nonProxyHosts>
    </proxy>
  </proxies>
  1. 请使用您的代理设置更改<host><port><username><password>
  2. 现在打开Eclipse。去Window - > Preference - > maven - > User Settings。现在在user settings输入框中给出settings.xml文件的路径,然后单击Apply然后单击Ok[screenshot for reference]

enter image description here

  1. 现在按Alt + F5并从列表中选择您的项目,然后选中force update of snapshot/release复选框并单击ok

以下是文档,如何为Maven配置代理服务器:https://maven.apache.org/guides/mini/guide-proxies.html


0
投票

谢谢Aagam Jain和veben。我尝试了这些步骤并没有奏效。原因是缺少代理服务器设置。

将代理设置添加到XML后,应用程序就构建并成功运行。它是在您的步骤和代理服务器设置的组合下运行的。

感谢帮助..

© www.soinside.com 2019 - 2024. All rights reserved.