java - 在 tomcat 上部署 Spring Boot 应用程序时出现 404 错误

标签 java spring tomcat http-status-code-404

当从 Eclipse 或 intellij idea 运行时,Spring Boot 应用程序运行在嵌入式 tomcat 服务器上。但是当部署在外部 tomcat 服务器上时,它会出现 404 错误。

最佳答案

确保您已完成以下步骤:

  1. 扩展 SpringBootServletInitializer
@SpringBootApplication
 public class SpringBootWebApplication extends SpringBootServletInitializer 
{

@Override
  protected SpringApplicationBuilder configure(SpringApplicationBuilder 
application) {
    return application.sources(SpringBootWebApplication.class);
   }

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

 }
  1. 将嵌入式 servlet 容器标记为 pom.xml 中提供的内容
<!-- marked the embedded servlet container as provided -->
  <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <scope>provided</scope>
  </dependency>
  1. 更新包装到 war

<packaging>war</packaging>

  • 将生成的 war 复制到 Tomcat 的 webapp 文件夹中并重新启动 tomcat。
  • 转到 tomcat 的管理页面,看看您是否可以找到您的应用程序及其状态正在运行/已启动。访问 URL 时,确保您附加了正确的上下文路径,如果在应用程序中使用“server.context”属性定义的话。属性文件。

如果您仍然遇到问题,请粘贴任何特定错误以防万一。

关于java - 在 tomcat 上部署 Spring Boot 应用程序时出现 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49305090/

相关文章:

xml - Spring STS servlet-context.xml 文件中的错误

java - 如何从 Spring 环境自动生成 postman 集合

java - 来自 context.xml 的 Maven 配置文件的不同资源

jakarta-ee - apache tomcat 服务器的日志文件

java - Java 中的 ActionListener 和 EventListener 有什么区别?

java - C++ 类中 'this' 指针可以为空吗?

java - Artemis-2.6.3 控制台 : Service Unavailable

spring - 严重 : Servlet threw load() exception javax. servlet.UnavailableException

java - Maven - `maven-archetype-simple` 是有效的原型(prototype)吗?

jsp - validateJarFile 未在 eclipse 和 netbeans 中加载