SpringBoot打包成war包(原创转载请附上博文链接)

博客介绍了SpringBoot项目相关操作。首先需创建SpringBoot项目,之后修改pom.xml增加war,修改启动类继承SpringBootServletInitializer类。若用Tomcat启动项目,可按指定链接步骤5操作;若要打war包,则按另一指定链接所有步骤操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  1. 先得有一个 SpringBoot 项目
    1.1 具体创建方法见
  2. 修改 pom.xml
    建完 SpringBoot 后一就增加一个war,其它没改
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>templates</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <!-- 修改 packaging 为 war -->
    <packaging>war</packaging>
    <name>templates</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

  1. 修改启动类﹡Application,继承 SpringBootServletInitializer 类
    如下:
@SpringBootApplication
public class TemplatesApplication extends SpringBootServletInitializer {

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

}
  1. 如果用 tomcat 启动项目
    https://blog.youkuaiyun.com/qq_23878541/article/details/90147223 的 步骤5 即可
  2. 如果想要打 war 包
    https://blog.youkuaiyun.com/qq_23878541/article/details/90158167 的 所有步骤 即可
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值