您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

如何在Tomcat服务器上部署Spring Boot Web应用程序

如何在Tomcat服务器上部署Spring Boot Web应用程序

这是有关如何将Spring Boot应用程序部署为war文件的两个很好的文档。

你可以按照此spring启动howto-Traditional-deployment 文档

根据此文档的步骤-

你将应用程序的主类更新为extend SpringBootServletInitializer

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

将嵌入式Servlet容器的相关性标记为已提供。

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

还有另一种方法

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

Steps

jar包装更改为war

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

通过扩展SpringBootServletInitializer和覆盖configure方法将Web入口点添加到你的应用程序中

删除spring-boot-starter-tomcat dependency修改你的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-beansspring-webmvc依赖项。该spring-boot-starter-web依存度将包括那些依赖条件。

Java 2022/1/1 18:13:50 有579人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶