Springboot项目部署到外置Tomcat
以前写过一个demo部署到tomcat很简单就没写文章记录一下,只是把遇到的问题记录了一下:错误记录,今天刚注册了一个域名心热试试看就部署一个新的demo进去源码,下面看步骤:
1.修改打包方式
<packaging>war</packaging>
2.不引入内置tomcat,引入单独包
<!--视图引擎thymeleaf-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<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>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-servlet-api</artifactId>
<version>8.0.36</version>
<scope>provided</scope>
</dependency>
这里我在spring-boot-starter-thymeleaf下面排除,因为spring-boot-starter-thymeleaf包含了spring-boot-starter-web
3.启动类继承SpringBootServletInitializer重写方法configure指向原启动类
public class SpringbootMybatisApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringbootMybatisApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(SpringbootMybatisApplication.class, args);
}
}
4.修改tomcat配置文件context.xml
TOMCAT_HOME\conf\context.xml
修改标签:<Context>
至<Context xmlBlockExternal="false">
好了,打包部署吧。