其实有点小问题。
我要切换我的bootstrap.yml的网址
它看起来如下:
spring:
application:
name: <project-name>
profiles:
active: dev
cloud:
config:
uri: http://<git-repository>:8080
fail-fast: false这是可行的,但我希望有一个属性或任何可以切换的东西,如果是在本地或其他环境。
我试着看这些文档,但没有看到任何工作为我。
发布于 2020-02-14 13:04:17
我不认为Spring与任何Spring应用程序有什么不同,所以您可以使用Spring配置文件。
在这个答案上也有类似的建议:https://stackoverflow.com/a/22759706/6908551。
您可以为云配置uri定义一个单独的.yml文件,比如cloud-config-dev.yml,cloud-config-prod.yml。然后,对于Java配置,您可以拥有如下内容:
@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;
}
}发布于 2020-02-14 13:44:36
我将按环境定义一个bootstrap.yml文件。
在src/main/resources中定义默认的bootstrap.yml文件,并为每个环境定义一个特定的bootstrap.yml文件。
那么有多种方法。
并非详尽无遗:
1)对于配置文件不同的每个环境,通过指定具有预期值的系统属性spring.cloud.bootstrap.location来运行spring,如:
java -jar ... -Dspring.cloud.bootstrap.location=bootstrap-dev.yml ...。
它覆盖该文件的当前位置。
2)利用Spring特性:bootstrap.yml兼容。例如,如果启用了dev配置文件,将使用类路径中的bootstrap-dev.properties。
我倾向于使用第一种方式,因为这对于非Spring用户来说更加明确。
来源:1.3改变自举特性的位置
https://stackoverflow.com/questions/60226678
复制相似问题