SpringBoot系列之jar包转war包

2019-08-02 15:22:11 浏览数 (1)

1.修改pom,将打包方式改为war包

2.dependencides中配置外部tomcat

代码语言:javascript复制
<!--因配置外部TOMCAT 而配置-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
代码语言:javascript复制

3.添加一个SpringBootServletInitializer 的继承类

代码语言:javascript复制
代码语言:javascript复制
package com.vrv.app;import org.springframework.boot.builder.SpringApplicationBuilder;import org.springframework.boot.web.support.SpringBootServletInitializer;/**
 * @Author:LJ
 * @Description:
 * @Date: 2018/5/18
 * @Modified By: */public class DemoInitializer extends SpringBootServletInitializer {
    @Override    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {        return builder.sources(HuaxiaApplication.class);
    }
}

4.main主类还是保持不变

代码语言:javascript复制
代码语言:javascript复制
package com.vrv.app;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplicationpublic class DemoApplication {    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }
}

0 人点赞