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

编程入门 行业动态 更新时间:2024-10-11 17:26:36
本文介绍了将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.

推荐答案

确保已完成以下步骤:

  • 扩展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); } }

  • 将嵌入式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>

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

    本文发布于:2023-10-28 10:56:10,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1536435.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:上时   应用程序   错误   Boot   Spring

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!