码迷,mamicode.com
首页 > 编程语言 > 详细

Spring-Boot项目部署到单独tomcat运行

时间:2019-08-27 23:09:14      阅读:107      评论:0      收藏:0      [点我收藏+]

标签:ram   div   void   war   boot   ons   ann   auto   aging   

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运行

标签:ram   div   void   war   boot   ons   ann   auto   aging   

原文地址:https://www.cnblogs.com/xiaofengfree/p/11420938.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!