部署在Tomcat上的Spring Boot Rest API可以提供404,但可以独立运行 [英] Spring Boot Rest API Deployed on Tomcat gives 404 but works Stand-alone all fine

查看:455
本文介绍了部署在Tomcat上的Spring Boot Rest API可以提供404,但可以独立运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大约一个月以来,我一直在使用MongoDB和嵌入式Tomcat来开发Spring Boot Rest API,以构建REST API.一切都很好.我现在想在一个单独的开发环境中部署该API,以便任何人都可以访问该API.

I have been working on Spring Boot Rest API using MongoDB with embedded Tomcat for about a month now to build a REST API. Everything was working fine. I now want to deploy the API in a separate development environment so that anybody can access the API.

我遵循了 http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file

  1. 将包装改为战争
  2. 将其添加到为spring-boot-starter-tomcat提供的pom.xml中
  3. 将我的应用程序扩展到SpringBootServletInitializer并改写了 配置方法.
  4. 我的application.properties具有以下内容:
    spring.data.rest.base-path =/
  1. Change the packaging to war
  2. Added this to my pom.xml provided for spring-boot-starter-tomcat
  3. extends my application to SpringBootServletInitializer and overwrote the configure method.
  4. my application.properties has this:
    spring.data.rest.base-path=/

完成所有这些操作后: 我尝试访问URL localhost:8080/my-war-name/employees,它给我404错误,但是如果我像通过main()那样与独立运行相同的应用程序,或者以Spring Boot的身份运行.我可以通过localhost:8080/employees

After doing all these: I tried accessing the URL localhost:8080/my-war-name/employees it gives me 404 error but if I run the same application as standalone like via main() or run as Spring Boot. I can access my API at localhost:8080/employees

我错过了什么吗?任何帮助将不胜感激.

Am I missing something? Any help would be appreciated.

推荐答案

您是否尝试过localhost:8080/employees?

Have you tried localhost:8080/employees ?

这取决于应用程序的上下文路径,如果要使用localhost:8080/my-war-name/employees,则可以添加

It depends what the app- context path, if you want localhost:8080/my-war-name/employees you can add

server.context-path = my-war-name到application.properties 有关配置的更多信息

server.context-path=my-war-name to application.properties More on config

这篇关于部署在Tomcat上的Spring Boot Rest API可以提供404,但可以独立运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆