springboot工程war包形式部署
springboot直接jar 启动,甚是方便,但是有一些场景,我们需要外部容器,就需要打成war包部署
上demo
首先 springboot-starter-web中需要去除内置的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依赖-->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
pom中打包方式改成war
<packaging>war</apckaging>
启动类中继承 SpringBootServletInitializer
public class MybatisPlusRun extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(MybatisPlusRun.class, args);
}
<!--重写configure方法-->
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return super.configure(builder);
}
}
用maven打包
mvn package
启动在浏览器访问即可