SpringBoot 项目开发完毕后,支持两种方式部署到服务器:
- jar包
- war包
打jar包
打war包
首先在pom文件中添加以下信息
<packaging>war</packaging>
#<bulid>标签下添加
<finalName>test1</finalName>
修改引导类
package com.yy.springboot_deploy;
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 SpringBootDeployApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(SpringBootDeployApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(SpringBootDeployApplication.class);
}
}
再打包就能打成war包,部署访问时注意,所有的路径相对于jar包直接访问的地址都要添加一个war包名称
如localhost:8080/test1/xxx