apolloconfig / apolloconfig/apollo

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

Abierto
#2,731 0 comentarios 0 reacciones 1 asignado Reclamado por @kangjiabang Ver en GitHub
feature request
Lenguaje dominante
Java
Estrellas
29.8k
Forks
10.2k
Merge medio
4 d 7 h
PR fusionados (30 d)
4

Descripción

现象:

- 在执行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)

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.