spring boot 不使用parent
阿新 • • 發佈:2019-01-04
建立 spring-boot 應用通用方法是配置 pom.xml,定義 為 spring-boot-start-parent。如下:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
</parent>
<dependencies>
<dependency >
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
但是在真正的專案開發中,往往模組需要定義自己的 而 maven 的 pom 只允許一個 存在,這種情況下,可以採用下面的定義來避免使用 spring-boot-start-parent。安裝如下配置的 pom.xml 可以通過 maven package 生成可以執行的 jar 包,通過 java -jar xxxx.jar 啟動執行。
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>1.4.0.RELEASE</version>
</dependency>
<!--ImportdependencymanagementfromSpringBoot-->
<dependency >
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>1.4.0.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.4.0.RELEASE</version>
<configuration>
<executable>true</executable>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>