问题描述
大约一个月以来,我一直在使用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.
- 将包装改为战争
- 将其添加到为spring-boot-starter-tomcat提供的pom.xml中
- 将我的应用程序扩展到SpringBootServletInitializer并改写了配置方法.
- 我的application.properties具有以下内容:
spring.data.rest.base-path =/
- Change the packaging to war
- Added this to my pom.xml provided for spring-boot-starter-tomcat
- extends my application to SpringBootServletInitializer and overwrote theconfigure method.
- 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.propertiesMore on config
这篇关于部署在Tomcat上的Spring Boot Rest API可以提供404,但可以独立运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!