一、通过jar包发布
1、在pom中添加一个SpringBoot的构建的插件
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<!--自动检测项目中的 main 函数-->
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
在maven视图中,选择"package",在target中会产生xxx.jar包
然后在cmd终端发布项目java -jar xxx.jar
二、通过war包发布
1、在pom.xml文件中将jar修改为war
<packaging>war</packaging>
2、设置tomcat启动器依赖范围
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<!--tomcat启动器依赖范围-->
<scope>provided</scope>
</dependency>
3、设置war包的名字(想设置可以设置,不想设置可以不设置)
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>hello</warName>
</configuration>
</plugin>
修改启动类
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 Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(Application.class);
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}