繁体   English   中英

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

[英]When Spring Boot app is deployed on tomcat gives 404 error

当从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. 更新包装以进行战争

<packaging>war</packaging>

  • 将生成的war复制到Tomcat的webapp文件夹中,然后重新启动tomcat。
  • 转到tomcat的管理页面,查看是否可以找到自己的应用,并且其状态正在运行/启动。访问URL时,请确保要附加正确的上下文路径(如果使用application.properties文件中的“ server.context”属性定义)。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM