如何在环境之间切换 URL?
How can I toggle URL between environments?
我一直在寻找一种方法来改变 url 我的微服务依赖于从一个环境到另一个环境,他们告诉我应该使用 spring 云,目前有一个用于在 openshift 中部署的 application.yml,但我对 Spring Cloud 的了解有限,我不知道如何将 application.yml URL 的值注入到我的 java 程序。
String uri = "http://127.0.0.1:8080/route";
我希望根据它是本地的还是在开发中来更改此变量
为什么?用于微服务之间的通信
private RestTemplate call = new RestTemplate();
Arrays.asList(call.getForObject(uri, Object[].class));
当地需要:"http://127.0.0.1:8080/route";
开发需要:"http://www.myurl.com/route"
我希望我解释得很好
谢谢。
正如 "M. Deinum" 和 "Ken de Guzman" 已经提到的,使用 "Spring Profiles" 方法。
在此处查看说明功能的文档:
- 外部配置:https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config
- 配置文件的使用:https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-profiles or https://springframework.guru/spring-profiles/
- 深入阅读:https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#beans-environment
好的,我想我的问题有解决方案了。
由于我使用 Openshift 进行部署,并使用本地配置进行其他操作,因此我将 Spring Cloud 与配置服务器一起使用,使其在本地使用一种配置,并在开发中使用另一种配置覆盖本地配置。
这解决了我的问题,感谢其他人回答任何解决方案。
我一直在寻找一种方法来改变 url 我的微服务依赖于从一个环境到另一个环境,他们告诉我应该使用 spring 云,目前有一个用于在 openshift 中部署的 application.yml,但我对 Spring Cloud 的了解有限,我不知道如何将 application.yml URL 的值注入到我的 java 程序。
String uri = "http://127.0.0.1:8080/route";
我希望根据它是本地的还是在开发中来更改此变量
为什么?用于微服务之间的通信
private RestTemplate call = new RestTemplate();
Arrays.asList(call.getForObject(uri, Object[].class));
当地需要:"http://127.0.0.1:8080/route";
开发需要:"http://www.myurl.com/route"
我希望我解释得很好
谢谢。
正如 "M. Deinum" 和 "Ken de Guzman" 已经提到的,使用 "Spring Profiles" 方法。
在此处查看说明功能的文档:
- 外部配置:https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-external-config
- 配置文件的使用:https://docs.spring.io/spring-boot/docs/current/reference/html/spring-boot-features.html#boot-features-profiles or https://springframework.guru/spring-profiles/
- 深入阅读:https://docs.spring.io/spring/docs/current/spring-framework-reference/core.html#beans-environment
好的,我想我的问题有解决方案了。 由于我使用 Openshift 进行部署,并使用本地配置进行其他操作,因此我将 Spring Cloud 与配置服务器一起使用,使其在本地使用一种配置,并在开发中使用另一种配置覆盖本地配置。
这解决了我的问题,感谢其他人回答任何解决方案。