Spring Boot application gives 404 when deployed to Tomcat but works with embedded server

后端 未结 3 978
温柔的废话
温柔的废话 2021-01-31 08:50

Guided by Serving Web Content with Spring MVC, I\'m creating a Spring Boot web application that I can run using both the embedded Tomcat instance as well as on a standalone Tomc

相关标签:
3条回答
  • 2021-01-31 08:50

    Just add the route in the controller annotation, something like this: @RestController @RequestMapping(value = "/")

    0 讨论(0)
  • 2021-01-31 08:54

    I had forgotten to tweak my Application.java file to extend SpringBootServletInitializer and override the configure method.

    Corrected file:

    @SpringBootApplication
    public class Application extends SpringBootServletInitializer {
      public static void main(String[] args) {
          SpringApplication.run(Application.class, args);
      }
    
      @Override
      protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
          return builder.sources(Application.class);
      }
    }
    

    Hat tip to https://mtdevuk.com/2015/07/16/how-to-make-a-spring-boot-jar-into-a-war-to-deploy-on-tomcat/ for pointing out my mistake.

    More info at Create a deployable war file in Spring Boot Official docs.

    0 讨论(0)
  • 2021-01-31 09:16

    In case anyone having same problem while using sprint boot in the IntelliJ community edition. You just need to put your main class in the main package (com.xyx) don't put it in any subpackage which is created inside com.xyx.

    0 讨论(0)
提交回复
热议问题