第一步:
将这个 Spring Boot 项目的打包方式设置为 war0.0.1 war
第二步
去掉springboot中内嵌的tomcat模块,修改pom文件org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-starter-tomcat
第三步
写一个SpringBootServletInitializer 子类,并覆盖它的 configure 方法,可以把应用的主类改为继承 SpringBootServletInitializer,或另外写,我这里用继承的方法
import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.boot.context.embedded.EmbeddedServletContainerCustomizer;import org.springframework.boot.web.servlet.ErrorPage;import org.springframework.boot.web.support.SpringBootServletInitializer;import org.springframework.context.annotation.Bean;import org.springframework.http.HttpStatus;import org.springframework.web.servlet.LocaleResolver;import org.springframework.web.servlet.i18n.CookieLocaleResolver;import java.util.Locale;@SpringBootApplicationpublic class RenProApplication extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure( SpringApplicationBuilder application) { return application.sources(RenProApplication.class); } public static void main(String[] args) { SpringApplication.run(RenProApplication.class, args); } @Bean public LocaleResolver localeResolver() { CookieLocaleResolver slr = new CookieLocaleResolver(); slr.setDefaultLocale(Locale.CHINA); slr.setCookieMaxAge(3600);//设置cookie有效期. return slr; }}
第四步
打包mvn clean package -Dmaven.test.skip=true
上传部署
scp -P 434 target/renpro-0.0.1.war root .12.31.222:/data
补充:
可以通过jar -xf renpro-0.0.1.war 解压,或者直接放到tomcat Host规定的目录中自动解压