Spring boot打war包

2022/9/16 23:19:43

本文主要是介绍Spring boot打war包,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

 

0. 添加war

 

 

 

1. 排除内置Tomcat
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <exclusions>
        <exclusion>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
        </exclusion>
    </exclusions>
</dependency>

 

2. 添加jar依赖
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>javax.servlet-api</artifactId>
    <version>3.1.0</version>
    <scope>provided</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
<dependency>
    <groupId>commons-codec</groupId>
    <artifactId>commons-codec</artifactId>
    <version>1.7</version>
</dependency>

 

3. Application修改

@SpringBootApplication
public class DemoCallApplication extends SpringBootServletInitializer {

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

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return builder.sources(DemoCallApplication.class);
    }
}

 

4.添加打包

<build>
        <finalName>democall</finalName>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>2.6.2</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-resources-plugin</artifactId>
                <version>2.6</version>
            </plugin>
        </plugins>
    </build>

 

5. package

 

 

 

 成功后把democall丢到Tomcat 的 webapps中 然后发布访问,注意前置是打包的名称,如果不想要可以放到tomcat的ROOT目录

 



这篇关于Spring boot打war包的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程