使用 1.5.9.RELEASE 更新 2018-01-04。
我在这里有完整的代码和可运行的示例https://www.surasint.com/spring-boot-with-no-parent-example/
你需要这个作为基础
<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${springframework.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
但这还不够,您还需要为 spring-boot-maven-plugin 显式定义目标(如果您使用 Spring Boot 作为父级,则不必显式定义它)
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${springframework.boot.version}</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
否则,您无法构建为可执行 jar 或 war。
还没有,如果你使用 JSP,你需要有这个:
<properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
否则,您将收到以下错误消息:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.2:war (default-war) on project spring-boot-09: Error assembling WAR: webxml attribute is required (or pre-existing WEB-INF/web.xml if executi
ng in update mode) -> [Help 1]
不不,如果您使用带有“@”而不是“${}”的 Spring Boot 的 Maven 配置文件和资源过滤器,这仍然不够(例如这个示例https://www.surasint.com/spring-boot-maven -资源过滤器/)。然后你需要明确地添加这个
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
而这在
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
<delimiters>
<delimiter>@</delimiter>
</delimiters>
<useDefaultDelimiters>false</useDefaultDelimiters>
</configuration>
</plugin>
请参阅链接https://www.surasint.com/spring-boot-with-no-parent-example/中的示例。