apolloconfig / apolloconfig/apollo

当ApolloPropertySources为null时,会将ProperitySources添加到env中,显示[]的列表

Aperta
#2,731 0 commenti 0 reazioni 1 assegnatario Rivendicata da @kangjiabang Vedi su GitHub
feature request
Lingua principale
Java
Stelle
29.8k
Fork
10.2k
Merge medio
4g 7h
PR unite (30g)
4

Descrizione

现象:

- 在执行PropertySourcesProcessor的initializePropertySources逻辑时,当未使用EnableApolloConfig注解时,NAMESPACE_NAMES列表为null,随后在添加ApolloPropertySources时,未进行列表判空操作,导致env中propertySources列表中会有ApolloPropertySources为[]的选项。

![image](https://user-images.githubusercontent.com/25074646/68186943-4d879880-ffe0-11e9-8706-12ee77f479d9.png)

修改方法:
1、将 ensureBootstrapPropertyPrecedence(environment)
的逻辑跟添加ApolloPropertySources到env中的逻辑分开,目的是不影响这段的执行。
2、添加ApolloPropertySources中列表的size判断操作。

`
if (composite.getPropertySources() != null && composite.getPropertySources().size() > 0) {
// add after the bootstrap property source or to the first
if (environment.getPropertySources()
.contains(PropertySourcesConstants.APOLLO_BOOTSTRAP_PROPERTY_SOURCE_NAME))
environment.getPropertySources()
.addAfter(PropertySourcesConstants.APOLLO_BOOTSTRAP_PROPERTY_SOURCE_NAME, composite);
} else {
environment.getPropertySources().addFirst(composite);
}
}`
* 修改后的结果

![image](https://user-images.githubusercontent.com/25074646/68187461-b02d6400-ffe1-11e9-857e-5d0d74490ee7.png)

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.