spring-boot打成war包放入tomcat运行

本文详细介绍如何将SpringBoot项目打包成WAR文件,并部署到Tomcat服务器上。包括集成SpringBootServletInitializer,修改pom.xml配置,以及编译打包过程。

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

转自: https://www.cnblogs.com/zhizou/p/11095469.html

springBoot项目打war包部署到tomcat上https://www.cnblogs.com/liyong888/p/8064169.html

springboot打包部署到tomcat:   https://www.cnblogs.com/gxlaqj/p/10263621.html

SpringBoot2.0版本打war包放入tomcat运行: https://blog.youkuaiyun.com/sJzao/article/details/84100129

SpringBoot2.0版本打war包放入tomcat部署方法:https://www.jb51.net/article/133160.htm

 

 

一、application集成SpringBootServletInitializer(重写configure方法)

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.boot.builder.SpringApplicationBuilder;

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

 

@SpringBootApplication

public class Hello2Application extends SpringBootServletInitializer {

    @Override

    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {

        //主要目的是构建成war包使用其他Web服务器去构建。

        return builder.sources(Hello2Application.class);

    }

 

    public static void main(String[] args) {

        SpringApplication.run(Hello2Application.class, args);

 

    }

 

}

二、配置pom.xml

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

<?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.6.RELEASE</version>

        <relativePath/> <!-- lookup parent from repository -->

    </parent>

    <groupId>com.example</groupId>

    <artifactId>hello2</artifactId>

    <version>0.0.1-SNAPSHOT</version>

    <name>hello2</name>

    <description>Demo project for Spring Boot</description>

 

    <!--改为war方式-->

    <packaging>war</packaging>

 

    <properties>

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

    </properties>

 

    <dependencies>

        <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<!--排除内置的Tomcat-->

                </exclusion>

            </exclusions>

        </dependency>

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-tomcat</artifactId>

            <!--打包的时候可以不用包进去,别的设施会提供。事实上该依赖理论上可以参与编译,测试,运行等周期。

                相当于compile,但是打包阶段做了exclude操作-->

            <scope>provided</scope>

        </dependency>

 

        <dependency>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-test</artifactId>

            <scope>test</scope>

        </dependency>

    </dependencies>

 

    <build><br>     <!-- war包的名字 -->

        <finalName>hello2</finalName>

        <plugins>

            <plugin>

                <groupId>org.springframework.boot</groupId>

                <artifactId>spring-boot-maven-plugin</artifactId>

            </plugin>

        </plugins>

    </build>

 

</project>

三、完成后进行编译打包

  编译:mvn clean compile

  打包:mvn clean package

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值