Springboot打包(一) jar包
2019-07-05 本文已影响0人
S拒绝拖延
1.配置server端口:
server:
port: 8080
2.在Maven中指定启动类,打包方式
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.example.XXX.XXX.DemoApplication</mainClass>
</configuration>
</plugin>
</plugins>
</build>
3.在启动类当中加上extends SpringBootServletInitializer并重写configure方法
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
@SpringBootApplication
public class SpringDemoApplication extends SpringBootServletInitializer{
public static void main(String[] args) {
SpringApplication.run(SpringDemoApplication .class, args);
}
@Override//为了打包springboot项目
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(this.getClass());
}
}
4.运行mvn clean 再 mvn install