在创建springboot项目时,如果使用Spring initializr创建项目,生成项目的pom文件是集成spring-boot-starter-parent的,在打包时默认会将所有的依赖打包。
打包插件默认配置如下:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
当我们不继承 spring-boot-starter-parent创建springboot项目时,pom文件的打包插件需要更改为如下:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.sample.SampleAppliation</mainClass> <!-- springboot的启动类全路径 -->
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
否则在打包时不会将依赖包打包进项目里面。