Java 如何从远程机器访问RESTAPI?

Java 如何从远程机器访问RESTAPI?,java,spring-boot,rest,http,tomcat,Java,Spring Boot,Rest,Http,Tomcat,我正在为移动应用程序编写spring服务(rest)。我正在使用localhost编写测试服务,并在虚拟机(windows)上运行,但我可以看到http://localhost:8080/rest仅在同一台计算机上。如何从另一台计算机使用rest api?ip aplication properties spring.data.mongodb.host=localhost spring.data.mongodb.port= spring.data.mongodb.database=mongoT

我正在为移动应用程序编写spring服务(rest)。我正在使用localhost编写测试服务,并在虚拟机(windows)上运行,但我可以看到
http://localhost:8080/rest
仅在同一台计算机上。如何从另一台计算机使用rest api?ip

aplication properties

spring.data.mongodb.host=localhost
spring.data.mongodb.port=
spring.data.mongodb.database=mongoTest

你在谈论两件不同的事情

您的属性文件是关于连接到mongodb实例的

localhost只是一个快捷方式,表示可以在本地计算机上找到应用程序

此属性文件中包含localhost意味着应用程序服务器和数据库服务器位于同一台物理计算机上

如果要从另一台计算机访问API,可以使用服务器的IP地址

在Windows上,您可以通过在命令行中键入ipconfig来了解此地址

在Linux上,应该是ifconfig


稍后,您可以尝试使用机器名而不是IP地址。

您可以使用公开API的机器的IP地址,从远程机器而不是本地主机访问它。在同一台计算机中访问Localhost时,可以使用Localhost。