记录一次springboot在idea打包war放服务器tomcat
前言
之前一直使用ssm框架,都是直接打包成war放服务器,但是springboot的一个运行不一样,使用的是内置的tomcat,在此记录一次将springboot项目打包成war
步骤
- 先将springboot内置的tomcat取出
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<!-- 取出tomcat -->
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
- 添加新的servlet依赖
<!-- httpServlet 依赖-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
- 添加打包方式,或者改为war
<description>Demo project for Spring Boot</description>
<packaging>war</packaging>
<properties>
<java.version>1.8</java.version>
</properties>
- 添加一个新的启动类,必须在原来的启动类的同级目录,其中启动类为xxxxxxxxxxxx
public class SpringBootStartApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(xxxxxxxxxxxx.class);
}
}
-
点击idea右上角的这个位置
-
查看war导出位置
-
-
点击bulid
-
-
点击导出
-
-
然后直接去导出的位置就可以看到war包了,上传的tomcat下的webapps就可以
-
ps: 因为一些直接入手springboot的朋友可能不知道,友情提醒一下,上传的服务器后,我们的请求url需要将如项目名的,如平时本地请求是http://localhost:8080/aaa,则放到服务器上就是 http://www.xxx.com/项目名/aaa