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

时间:2018-03-15 16:54:17

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

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

1 个答案:

答案 0 :(得分:3)

确保您已完成以下步骤:

  1. 扩展SpringBootServletInitializer
  2. @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. 标记pom.xml
    2. 中提供的嵌入式servlet容器
      <!-- marked the embedded servlet container as provided -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
      
      1. 将包装更新为战争
      2.   

        <packaging>war</packaging>

        • 将生成的战争复制到Tomcat的webapp文件夹中,然后重新启动tomcat。
        • 转到tomcat的管理页面,查看是否可以找到您的应用程序并且其状态正在运行/已启动。访问URL时,请确保添加正确的上下文路径,如果使用&#34; server.context&#34定义; application.properties文件中的属性。

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

相关问题