sping boot 打war 包 在tomcat 中运行

来源:互联网 发布:atmega dip封装单片机 编辑:程序博客网 时间:2024/05/17 06:28

import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class App {    public static void main(String[] args) {        SpringApplication.run(App.class, args);    }}

sping boot  打war 包 到tomcat中运行 

环境

1 :tomcat8

2 :sping boot 1.33 

 



pom.xml

 <dependencies>        <!-- web支持: 1、web mvc; 2、restful; 3、jackjson支持; 4、aop ........ -->        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-web</artifactId>        </dependency>        <!-- servlet 依赖. -->        <dependency>            <groupId>javax.servlet</groupId>            <artifactId>javax.servlet-api</artifactId>            <scope>provided</scope>        </dependency>        <dependency>            <groupId>javax.servlet</groupId>            <artifactId>jstl</artifactId>        </dependency>        <!-- tomcat 的支持.-->        <dependency>            <groupId>org.springframework.boot</groupId>            <artifactId>spring-boot-starter-tomcat</artifactId>            <scope>provided</scope>        </dependency>        <dependency>            <groupId>org.apache.tomcat.embed</groupId>            <artifactId>tomcat-embed-jasper</artifactId>            <scope>provided</scope>        </dependency>    </dependencies>
打成war 包的时候 要去除 <!-- tomcat 的支持.-->另外  还要添加一个启动类原来的启动类不变:
import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class App {    public static void main(String[] args) {        SpringApplication.run(App.class, args);    }}
新增加一个启动类 目地是为了让tomcat 启动原来的启动类
import org.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.boot.context.web.SpringBootServletInitializer;  public class ServletInitializer extends SpringBootServletInitializer {      @Override      protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {          return application.sources(App.class);    }  }  
设置完毕后 打成 war 包


 
原创粉丝点击