自动化Spring Cloud配置文件 [英] Automatization Spring Cloud Profile
问题描述
实际上有一点问题.
我想切换bootstrap.yml的网址
I want switch the url of my bootstrap.yml
它看起来如下:
spring:
application:
name: <project-name>
profiles:
active: dev
cloud:
config:
uri: http://<git-repository>:8080
fail-fast: false
这行得通,但是我想拥有一个物业或任何在本地或其他环境中可以切换的东西.
This works, but i want have an propertie or anything what can switch if are in local or another enviroment.
我尝试查看此文档,但看不到对我有任何帮助.
I try to see this documentation but dont see any work for me.
推荐答案
我认为Spring Cloud与任何Spring应用程序都没有什么不同,因此您可以使用Spring配置文件.
I don't think Spring Cloud is any different from any Spring application, so you could use the Spring profiles.
对此答案的建议类似: https://stackoverflow.com/a/22759706/6908551 .
Something similar is suggested on this answer: https://stackoverflow.com/a/22759706/6908551.
您可以仅为您的云配置uri定义一个单独的 .yml
文件,例如 cloud-config-dev.yml
, cloud-config-prod.yml
.然后,对于Java配置,您可能会有类似的内容:
You could define a separate .yml
file just for your cloud config uri, like cloud-config-dev.yml
, cloud-config-prod.yml
. Then, for a Java config, you could have something like:
@Configuration
public class MyApplicationConfiguration {
@Bean
public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
String activeProfile = System.getProperty("spring.profiles.active", "production");
String ymlFilename = "cloud-config-" + activeProfile + ".yml";
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
configurer.setLocation(new ClassPathResource(ymlFilename));
return configurer;
}
}
这篇关于自动化Spring Cloud配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!