1. 程式人生 > >springboot專案不適用parent依賴,導致maven依賴無效

springboot專案不適用parent依賴,導致maven依賴無效

springboot專案的構建一般存在如下依賴:

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

如果刪除這個依賴,會出現如下圖問題:

解決辦法,引入maven依賴:

<dependencyManagement>
<dependencies>
<dependency>
<!-- Import dependency management from Spring Boot -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.5.6.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

j經測試,打包的話,不能執行,不能使用java -jar demo.jar執行,會報錯沒有主清單。

必須新增如下外掛

<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.transferservice.TransferServiceApplication</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>

經測試,打包之後,使用命令java -jar demo.jar專案可以正常啟動。