且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在tomcat服务器上部署spring boot web应用程序

更新时间:2023-08-21 10:33:58

以下是关于如何将 Spring Boot 应用程序部署为 war 文件的两个好文档。

Here are two good documentations on how to deploy the Spring Boot App as a war file.

你可以按照这个春季启动 howto-traditional-deployment 文档 -

You can follow this spring boot howto-traditional-deployment documentation -

根据此文档执行的步骤 -

Steps according to this documentation -


  1. 您更新应用程序的主类以扩展 SpringBootServletInitializer

下一步是更新构建配置,以便项目生成war文件而不是jar文件。 < packaging> war< / packaging>

The next step is to update your build configuration so that your project produces a war file rather than a jar file. <packaging>war</packaging>

标记提供的嵌入式servlet容器依赖项。

Mark the embedded servlet container dependency as provided.

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


还有一种方式 -

请参阅 spring io文档,其中概述了如何将spring boot应用程序部署到应用程序服务器。

See this spring io documentation which outlines how to deploy the spring boot app to an application server.

步骤 -


  1. jar 打包改为 war

注释掉 spring-boot-maven-plugin 的声明> pom.xml中的插件

通过扩展 SpringBootServletInitializer 并覆盖 configure 方法

删除 spring-boot-starter-tomcat依赖并修改你的 spring-boot-starter-web 依赖




<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>


pom.xml中,删除 spring-beans spring-webmvc 依赖项。 spring-boot-starter-web 依赖项将包括这些依赖项。

In your pom.xml, remove spring-beans and spring-webmvc dependencies. The spring-boot-starter-web dependency will include those dependecies.