如何在tomcat应用服务器上部署ee war文件

问题描述 投票:0回答:1

我有可运行的 springboot(2.4) Java(8) 项目,它与带有 .jar 扩展名的嵌入式 tomcat(10) 一起工作得很好。我需要在 tomcat 应用程序服务器上运行相同的项目,但在我将其更改为 war 并部署之后进入 tomcat 应用程序服务器,它给出 404 错误消息。我是否需要做一些额外的工作才能部署在 tomcat 应用程序服务器上。

我的主要课程如下,

@ComponentScan("com.example.testproject")
@SpringBootApplication
@EnableSwagger2
@Slf4j
@EnableAutoConfiguration
public class ApplicationStarter extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return configureApplication(builder);
    }
    public static void main(String[] args) {
        SpringApplication app = new SpringApplication(ApplicationStarter.class);
        app.setBannerMode(Banner.Mode.OFF);
        app.run(args);
    }
    private static SpringApplicationBuilder configureApplication(SpringApplicationBuilder builder) {    
        return builder.sources(ApplicationStarter.class);
    }
}

我还添加了以下依赖项,

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

<groupId>com.example</groupId>
<artifactId>testproject</artifactId>
<version>0.0.1-testproject</version>
<packaging>war</packaging> // earlier it was jar and with embedded tomcat its working 
java spring-boot tomcat java-8 tomcat10
1个回答
0
投票

除了您已经执行的步骤之外,您还应该将其添加到

pom.xml

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

通过定义

scope = provided
,您可以防止 Spring Boot 启动嵌入式 Tomcat。重新打包项目后,您可以将 WAR 文件复制到外部 Tomcat 并重新启动它。

基于:https://www.baeldung.com/spring-boot-war-tomcat-deploy

© www.soinside.com 2019 - 2024. All rights reserved.