将Spring Boot应用程序部署在tomcat上时出现404错误 [英] When Spring Boot app is deployed on tomcat gives 404 error

查看:119
本文介绍了将Spring Boot应用程序部署在tomcat上时出现404错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Spring Boot application runs on embedded tomcat server when run it from Eclipse or intellij idea. But when deployed on external tomcat server it gives 404 error.

推荐答案

确保已完成以下步骤:

  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. 将包装更新为战争

< packaging> war</packaging>

  • 将产生的战争复制到Tomcat的webapp文件夹中,然后重新启动tomcat.
  • 转到tomcat的管理页面,查看是否可以找到您的应用,并且其状态正在运行/启动.访问URL时,请确保您附加了正确的上下文路径(如果使用应用程序中的"server.context"属性进行了定义).属性文件.
  • 如果仍然遇到问题,请粘贴任何特定的错误,以防万一.

    Paste any specific error in case otherwise,if you still face the issue.

    这篇关于将Spring Boot应用程序部署在tomcat上时出现404错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆