在 Spring 引导中使用环境变量

Using Environment variables in Spring boot

我正在使用 sprint 启动。我想检查 spring 启动应用程序 运行 的当前位置。我想出了在 spring 上使用环境变量,但不知道如何获取位置。

环境变量应发送当前应用程序的位置 运行,因为它可以部署在不同的位置,例如:U.S/India.

提前致谢

在我看来,解决方案分为两步:

第 1 步:获取正在执行代码的机器的 public IP。

URL whatismyip = new URL("http://checkip.amazonaws.com");
BufferedReader in = new BufferedReader(new InputStreamReader(whatismyip.openStream()));
String ip = in.readLine(); // Public IP of machine

第 2 步:通过该 IP 地址获取位置

为此,您可以使用 MaxMind GeoIP Lite 数据库,如 here in another answer or article 中所述。