SpringBoot如何进行项目打包部署

2025-01-24 08:48:18
推荐回答(1个)
回答1:

1. springboot的打包方式有很多种。有打成war的,有打成jar的,也有直接提交到github

首先需要在application.properties当中配置端口

server.port=8080

2. marven的配置文件

xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0

com.weixin
smallsystem
0.0.1-SNAPSHOT
jar

smallsystem
smallsystem


org.springframework.boot
spring-boot-starter-parent
2.0.0.RELEASE




UTF-8
UTF-8
1.8




org.springframework.boot
spring-boot-starter-web



org.springframework.boot
spring-boot-starter-test
test



io.springfox
springfox-swagger2
2.2.2


io.springfox
springfox-swagger-ui
2.2.2



org.springframework.boot
spring-boot-devtools
true







org.springframework.boot
spring-boot-maven-plugin

com.weixin.SmallsystemApplication






在启动类当中加上extends SpringBootServletInitializer并重写configure方法,这是为了打包springboot项目用的。
@SpringBootApplication
public class SmallsystemApplication extends SpringBootServletInitializer{

public static void main(String[] args) {
SpringApplication.run(SmallsystemApplication.class, args);
}

@Override//为了打包springboot项目
protected SpringApplicationBuilder configure(
SpringApplicationBuilder builder) {
return builder.sources(this.getClass());
}
}
然后按照顺序运行mvn clean再mvn install