欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

springBoot Maven改成war包

程序员文章站 2024-02-07 16:42:40
...

1.在项目的pom.xml中添加

    <packaging>war</packaging>


        <dependencies>
        //自己对比下,缺哪些
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <!-- 移除嵌入式tomcat插件 -->
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
           <!--移除自带的tomcat-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

2.修改启动类 新建SpringBootStartApplication类

package com.xianbaovip.project;

import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

public class SpringBootStartApplication extends SpringBootServletInitializer {

    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder){
    
    //ProjectApplication为原来的启动类
            return builder.sources(ProjectApplication.class);
            
    }
}

springBoot Maven改成war包
3.打包
springBoot Maven改成war包
4.查看 在target目录下
springBoot Maven改成war包

相关标签: 打包 Springboot