springboot项目如何打war包以及无法ADD到tomcat服务的解决方案
一、修改打包形式
在pom.xml里设置
<packaging>war</packaging>
二、移除嵌入式tomcat插件
在pom.xml里找到
spring-boot-starter-web
依赖节点,在其中添加如下代码,
<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-api的依赖
下面两种方式都可以,任选其一
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>8.0.36</version>
<scope>provided</scope>
</dependency>
四、无法ADD到tomcat服务解决方案
1、右键点击项目,选择properties
2、点击Project facets
3、在右侧的Runtimes中选中apache tomcat
4、勾选Dynamic Web Module
最终改为下面的样式,其余的不要:
即可通过add and remove部署该项目。