Spring-Boot项目部署到单独tomcat运行
Posted xiaofengfree
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spring-Boot项目部署到单独tomcat运行相关的知识,希望对你有一定的参考价值。
1、pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.shunneng.springboot</groupId> <artifactId>springboot-demo2</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.1.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-tomcat</artifactId> <scope>provided</scope> </dependency> </dependencies> </project>
2、启动类需要继承SpringBootServletInitializer
import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; @SpringBootApplication @Controller public class HelloSpringBoot extends SpringBootServletInitializer @RequestMapping("/hello") @ResponseBody public String hello() return "hello springboot"; @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) return builder.sources(HelloSpringBoot.class); /** * springboot执行入口 */ public static void main(String[] args) //SpringApplication.run(HelloSpringBoot.class, args); //不需要额外启动设置可以使用这一行代替 SpringApplication application = new SpringApplication(HelloSpringBoot.class); // application.setBannerMode(Mode.OFF);//关闭banner application.run(args);
以上是关于Spring-Boot项目部署到单独tomcat运行的主要内容,如果未能解决你的问题,请参考以下文章
Eclipse中创建新的SpringBoot项目(打包并且部署到tomcat)
我是否需要单独为Spring-boot项目安装Tomcat?