idea新建springboot项目并且调试成功后,因为springboot项目默认是在内嵌的tomcat上运行的,这里就说一下springboot项目如何发布在外部tomcat服务器上,包括idea开发工具中用tomcat运行。
简单的只记录流程,和简单的解释。
1、移除springboot默认内嵌的tomcat
找到pom中依赖的spring-boot-starter-web
-
<dependency>
-
<groupId>org.springframework.boot </groupId>
-
<artifactId>spring-boot-starter-web </artifactId>
-
<exclusions>
-
<exclusion>
-
<groupId>org.springframework.boot </groupId>
-
<artifactId>spring-boot-starter-tomcat </artifactId>
-
</exclusion>
-
</exclusions>
-
</dependency>
或者
-
<dependency>
-
<groupId>org.springframework.boot </groupId>
-
<artifactId>spring-boot-starter-tomcat </artifactId>
-
<scope>provided </scope>
-
</dependency>
-
<build>
-
<plugins>
-
<plugin>
-
<groupId>org.springframework.boot </groupId>
-
<artifactId>spring-boot-maven-plugin </artifactId>
-
</plugin>
-
</plugins>
-
-
<finalName>demo </finalName>
-
</build>
2、修改打包方式
<packaging>war</packaging>
3、修改启动代码
我们一定要重写springboot的入口main:
注意点:
因为springboot默认tomcat是8版本,由于我们使用的tomcat版本过低,所以同样会出现各种奇葩问题,所以,直接使用tomcat8版本,避免一些奇葩问题