@SpringBootApplication(scanBasePackages = {"com.xxx.*"}) public class ApiApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(ApiApplication.class); } public static void main(String[] args) { SpringApplication.run(ApiApplication.class, args); } }
api的pom.xml
<build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <configuration> <!-- 指定该Main Class为全局的唯一入口 --> <mainClass>com.xxx.api.ApiApplication</mainClass> <layout>ZIP</layout> </configuration> <executions> <execution> <goals> <goal>repackage</goal><!--可以把依赖的包都打包到生成的Jar包中--> </goals> </execution> </executions> </plugin> <!--maven打包排除spring-boot内嵌tomcat容器依赖jar--> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.0.0</version> <configuration> <!--打包后的名称--> <warName>xxx-api</warName> <packagingExcludes> WEB-INF/lib/tomcat-embed-*.jar, WEB-INF/lib/spring-boot-starter-tomcat-*.jar </packagingExcludes> </configuration> </plugin> </plugins> </build>
cmd进入项目根目录单独打包api模块:
mvn -pl xxx-api -am install