简体   繁体   English

使用spring-boot-starter-web的Spring Boot无法在Maven中编译

[英]Spring Boot with spring-boot-starter-web fails to compile in maven

I am using jdk1.7 and spring boot 1.4.2.Release.I created a brand new Spring boot project from start.spring.io. 我正在使用jdk1.7和spring boot 1.4.2.Release。我从start.spring.io创建了一个全新的Spring boot项目。 It compiled fine. 它编译良好。 I tried to add the below dependency for exposing a REST web service. 我试图添加以下依赖项以公开REST Web服务。

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

I get the below error: 我收到以下错误:

[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-
web:jar:1.4.2.RELEASE -> org.hibernate:hibernate-validator:jar:5.2.4.Final: 
Failed to read artifact descriptor for org.hibernate:hibernate-
validator:jar:5.2.4.Final: Could not transfer artifact 
org.jboss.shrinkwrap:shrinkwrap-bom:pom:1.2.2 from/to spring-ext 
(http://repo.spring.io/ext-release-local/): repo.spring.io: Unknown host 
repo.spring.io -> [Help 1]

It takes the http://repo.spring.io/ext-release-local link which does not have jboss related files. 它带有http://repo.spring.io/ext-release-local链接,该链接没有jboss相关文件。

Please let me know if I am doing something wrong. 如果我做错了事,请告诉我。

Your pom should look like this

<?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.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.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-data-rest</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>
    </dependencies>

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


</project>

after that you need to run it with command mvn spring-boot:run from the project directory 之后,您需要从项目目录使用命令mvn spring-boot:run运行它

I hope this time it will defenetly work only need to copy and pase this pom content to your pom file 我希望这一次它将不再使用,仅需要将此pom内容复制并插入到您的pom文件中

To build spring boot application from scratch you can follow the link 要从头开始构建Spring Boot应用程序,您可以点击链接

In my case, just adding the repository configuration to the pom.xml didn't work. 就我而言,仅将存储库配置添加到pom.xml中是行不通的。 I had to add the following code into /maven-installation-dir/conf/settings.xml file. 我必须将以下代码添加到/maven-installation-dir/conf/settings.xml文件中。

<mirror>
    <id>central-proxy</id>
    <name>central-proxy</name>
    <url>http://corporate-intranet/repo/url</url>
    <mirrorOf>central</mirrorOf></mirror>

I hope it helps someone. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在没有 spring-boot-starter-web 的情况下配置 Spring Security AuthenticationManager - Configure Spring Security AuthenticationManager without spring-boot-starter-web spring initializr:spring-boot-starter vs spring-boot-starter-web - spring initializr: spring-boot-starter vs spring-boot-starter-web @CrossOrigin 不适用于 spring-boot-starter-web 2.5.2 - @CrossOrigin not working for spring-boot-starter-web 2.5.2 如何限制 spring-boot-starter-web 中的完整有效负载大小? - How to limit full payload size in spring-boot-starter-web? 结合 ObjectDB 使用 Spring-Boot-Starter-Web - Using Spring-Boot-Starter-Web in combination with ObjectDB spring-boot-starter-web @Autowired无效 - spring-boot-starter-web @Autowired isn't working 使用 spring-boot-starter-web “找不到可接受的表示” - "Could not find acceptable representation" using spring-boot-starter-web spring-boot-starter-web和spring-boot-starter-web-services以及spring-boot-starter-jersey之间的区别 - Difference between spring-boot-starter-web and spring-boot-starter-web-services and spring-boot-starter-jersey spring-boot-starter-tomcat vs spring-boot-starter-web - spring-boot-starter-tomcat vs spring-boot-starter-web 切换spring-boot-starter-jersey的spring-boot-starter-web时的奇怪行为 - Odd behavior when switching spring-boot-starter-web for spring-boot-starter-jersey
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM