下面列出了org.springframework.core.env.MutablePropertySources#precedenceOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void orderingIsCorrect() {
refresher.refresh();
MutablePropertySources propertySources = environment.getPropertySources();
PropertySource<?> test1 = propertySources
.get("bootstrapProperties-testContextRefresherOrdering1");
PropertySource<?> test2 = propertySources
.get("bootstrapProperties-testContextRefresherOrdering2");
PropertySource<?> test3 = propertySources
.get("bootstrapProperties-testContextRefresherOrdering3");
int index1 = propertySources.precedenceOf(test1);
int index2 = propertySources.precedenceOf(test2);
int index3 = propertySources.precedenceOf(test3);
assertThat(index1).as("source1 index not less then source2").isLessThan(index2);
assertThat(index2).as("source2 index not less then source3").isLessThan(index3);
}
private void ensureBootstrapPropertyPrecedence(ConfigurableEnvironment environment) {
MutablePropertySources propertySources = environment.getPropertySources();
PropertySource<?> bootstrapPropertySource = propertySources
.get(PropertySourcesConstants.APOLLO_BOOTSTRAP_PROPERTY_SOURCE_NAME);
// not exists or already in the first place
if (bootstrapPropertySource == null || propertySources.precedenceOf(bootstrapPropertySource) == 0) {
return;
}
propertySources.remove(PropertySourcesConstants.APOLLO_BOOTSTRAP_PROPERTY_SOURCE_NAME);
propertySources.addFirst(bootstrapPropertySource);
}
@Test
public void orderingIsCorrect() {
MutablePropertySources propertySources = environment.getPropertySources();
PropertySource<?> test1 = propertySources
.get("bootstrapProperties-testBootstrap1");
PropertySource<?> test2 = propertySources
.get("bootstrapProperties-testBootstrap2");
PropertySource<?> test3 = propertySources
.get("bootstrapProperties-testBootstrap3");
int index1 = propertySources.precedenceOf(test1);
int index2 = propertySources.precedenceOf(test2);
int index3 = propertySources.precedenceOf(test3);
assertThat(index1).as("source1 index not less then source2").isLessThan(index2);
assertThat(index2).as("source2 index not less then source3").isLessThan(index3);
}