其他分享
首页 > 其他分享> > Spring boot打war包

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,springframework,class,DemoCallApplication,Spring,org,war
来源: https://www.cnblogs.com/eason-d/p/16701173.html