Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Boot中使用SpringApplicationRunListener初始化Apollo的PropertySource #942

Closed
wants to merge 4 commits into from

Conversation

tastypinenut
Copy link

No description provided.

胡昇 and others added 4 commits January 17, 2018 11:03
2. Reorganize the feature to provide the ability to inject apollo
configs in Spring Boot bootstrap phase
3. Add more integration tests to cover different scenarios
4. Update apollo-demo to show this apollo bootstrap config feature could
be used with @ConditionalOnProperty
composite.addPropertySource(new ConfigPropertySource(namespace, config));
}

environment.getPropertySources().addFirst(composite);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议放到systemEnvironment之后,方便开发测试时通过系统变量临时更改参数,代码如下:
propertySources.addAfter(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, composite);

优先级如下所示:

StubPropertySource {name='servletConfigInitParams'}
StubPropertySource {name='servletContextInitParams'}
MapPropertySource {name='systemProperties'}
SystemEnvironmentPropertySource {name='systemEnvironment'}
CompositePropertySource [name='ApolloPropertySources', propertySources=[ConfigPropertySource {name='application'}]]
RandomValuePropertySource {name='random'}
PropertiesPropertySource {name='applicationConfig: [classpath:/application-local.properties]'}
PropertiesPropertySource {name='applicationConfig: [classpath:/application.properties]'}
MapPropertySource {name='refresh'}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在apollo中已经把system property放在前面了,所以在spring这里应该不需要了,详见 https://github.com/ctripcorp/apollo/blob/master/apollo-client/src/main/java/com/ctrip/framework/apollo/internals/DefaultConfig.java#L67

system environment我们是考虑用的比较少,所以是放在apollo后面,作为fallback使用

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

原因如此,谢谢您的解释

@nobodyiam
Copy link
Member

@tastypinenut 这个PR的改动之前已经通过 #937 合并到master了,所以这个PR先关闭了~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants