Spring Boot Deployed in Tomcat gives 404 but works Stand-alone

前端 未结 3 455
孤城傲影
孤城傲影 2021-01-04 09:29

I have been testing Spring Boot with embedded Tomcat for about a month now to build a REST API. Everything was working fine. We now want to deploy the API in a separate deve

相关标签:
3条回答
  • 2021-01-04 09:46

    check java -version means the if you complied war in java 8 and tomcat is running on java 7 then it doesn't work.

    0 讨论(0)
  • 2021-01-04 09:48

    When running an application the path to call consists of a couple of parts.

    The first is the base URL on which the application is deployed, in your case that is /sophia.

    The second is the servlet mapping of the DispatcherServlet in your case that is /sohpia/*.

    The third is the mapping of the controller inside the DispatcherServlet, in your example that is /users.

    All those things combined create the URL /sophia/sophia/users.

    The difference between the deployment as a WAR is that you included a separate URL to deploy on, when running as a jar it, by default, is deployed to / (the root).

    You could fix it by putting /sophia as the server.context-path in the application.properties and map the DispatcherServlet to /* or /. That will in both situations give you the URL you want (and expected).

    0 讨论(0)
  • 2021-01-04 09:56

    Have you tried extending the SpringBootServletInitializer and overriding the configure method? As stated here

    The entry point for jar file is different [Main Class] when compared to running your app as war file inside a container.

    Hope this helps.

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