本文整理汇总了Java中org.springframework.core.env.ConfigurableEnvironment.getPropertySources方法的典型用法代码示例。如果您正苦于以下问题:Java ConfigurableEnvironment.getPropertySources方法的具体用法?Java ConfigurableEnvironment.getPropertySources怎么用?Java ConfigurableEnvironment.getPropertySources使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.core.env.ConfigurableEnvironment
的用法示例。
在下文中一共展示了ConfigurableEnvironment.getPropertySources方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: postProcessEnvironment
import org.springframework.core.env.ConfigurableEnvironment; //导入方法依赖的package包/类
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
// 此处可以http方式 到配置服务器拉取一堆公共配置+本项目个性配置的json串,拼到Properties里
// ......省略new Properties的过程
MutablePropertySources propertySources = environment.getPropertySources();
// addLast 结合下面的 getOrder() 保证顺序 读者也可以试试其他姿势的加载顺序
try {
Properties props = getConfig(environment);
for (Object key : props.keySet()) {
String keyStr = key.toString();
String value = props.getProperty(keyStr);
if ("druid.writer.password,druid.reader.password".contains(keyStr)) {
String dkey = props.getProperty("druid.key");
dkey = DataUtil.isEmpty(dkey) ? Constants.DB_KEY : dkey;
value = SecurityUtil.decryptDes(value, dkey.getBytes());
props.setProperty(keyStr, value);
}
PropertiesUtil.getProperties().put(keyStr, value);
}
propertySources.addLast(new PropertiesPropertySource("thirdEnv", props));
} catch (IOException e) {
logger.error("", e);
}
}
示例2: addDefaultProperty
import org.springframework.core.env.ConfigurableEnvironment; //导入方法依赖的package包/类
private void addDefaultProperty(ConfigurableEnvironment environment, String name,
String value) {
MutablePropertySources sources = environment.getPropertySources();
Map<String, Object> map = null;
if (sources.contains("defaultProperties")) {
PropertySource<?> source = sources.get("defaultProperties");
if (source instanceof MapPropertySource) {
map = ((MapPropertySource) source).getSource();
}
} else {
map = new LinkedHashMap<>();
sources.addLast(new MapPropertySource("defaultProperties", map));
}
if (map != null) {
map.put(name, value);
}
}
示例3: findProps
import org.springframework.core.env.ConfigurableEnvironment; //导入方法依赖的package包/类
public static Properties findProps(ConfigurableEnvironment env, String prefix){
Properties props = new Properties();
for (PropertySource<?> source : env.getPropertySources()) {
if (source instanceof EnumerablePropertySource) {
EnumerablePropertySource<?> enumerable = (EnumerablePropertySource<?>) source;
for (String name : enumerable.getPropertyNames()) {
if (name.startsWith(prefix)) {
props.putIfAbsent(name, enumerable.getProperty(name));
}
}
}
}
return props;
}
示例4: initialize
import org.springframework.core.env.ConfigurableEnvironment; //导入方法依赖的package包/类
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
final ConfigurableEnvironment configurableEnvironment = applicationContext.getEnvironment();
configurableEnvironment.setDefaultProfiles(Constants.STANDARD_DATABASE);
final MutablePropertySources propertySources = configurableEnvironment.getPropertySources();
AwsCloudRuntimeConfig.createPropertySource().ifPresent(awsPropertySource -> {
propertySources.addLast(awsPropertySource);
LOG.info("Using Amazon RDS profile");
configurableEnvironment.setActiveProfiles(Constants.AMAZON_DATABASE);
});
LiquibaseConfig.replaceLiquibaseServiceLocator();
}
示例5: postProcessBeanFactory
import org.springframework.core.env.ConfigurableEnvironment; //导入方法依赖的package包/类
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
throws BeansException {
ConfigurableEnvironment env = beanFactory.getBean(ConfigurableEnvironment.class);
MutablePropertySources propertySources = env.getPropertySources();
registerPropertySources(
beanFactory.getBeansOfType(
org.springframework.vault.core.env.VaultPropertySource.class)
.values(), propertySources);
registerPropertySources(
beanFactory
.getBeansOfType(
org.springframework.vault.core.env.LeaseAwareVaultPropertySource.class)
.values(), propertySources);
}
示例6: configurePropertySources
import org.springframework.core.env.ConfigurableEnvironment; //导入方法依赖的package包/类
/**
* Add, remove or re-order any {@link PropertySource}s in this application's
* environment.
* @param environment this application's environment
* @param args arguments passed to the {@code run} method
* @see #configureEnvironment(ConfigurableEnvironment, String[])
*/
protected void configurePropertySources(ConfigurableEnvironment environment,
String[] args) {
MutablePropertySources sources = environment.getPropertySources();
if (this.defaultProperties != null && !this.defaultProperties.isEmpty()) {
sources.addLast(
new MapPropertySource("defaultProperties", this.defaultProperties));
}
if (this.addCommandLineProperties && args.length > 0) {
String name = CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME;
if (sources.contains(name)) {
PropertySource<?> source = sources.get(name);
CompositePropertySource composite = new CompositePropertySource(name);
composite.addPropertySource(new SimpleCommandLinePropertySource(
name + "-" + args.hashCode(), args));
composite.addPropertySource(source);
sources.replace(name, composite);
}
else {
sources.addFirst(new SimpleCommandLinePropertySource(args));
}
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:30,代码来源:SpringApplication.java
示例7: postProcessEnvironment
import org.springframework.core.env.ConfigurableEnvironment; //导入方法依赖的package包/类
@Override
public void postProcessEnvironment(ConfigurableEnvironment environment,
SpringApplication application) {
if (CloudPlatform.CLOUD_FOUNDRY.isActive(environment)) {
Properties properties = new Properties();
addWithPrefix(properties, getPropertiesFromApplication(environment),
"vcap.application.");
addWithPrefix(properties, getPropertiesFromServices(environment),
"vcap.services.");
MutablePropertySources propertySources = environment.getPropertySources();
if (propertySources.contains(
CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME)) {
propertySources.addAfter(
CommandLinePropertySource.COMMAND_LINE_PROPERTY_SOURCE_NAME,
new PropertiesPropertySource("vcap", properties));
}
else {
propertySources
.addFirst(new PropertiesPropertySource("vcap", properties));
}
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:23,代码来源:CloudFoundryVcapEnvironmentPostProcessor.java
示例8: matchingPropertySource
import org.springframework.core.env.ConfigurableEnvironment; //导入方法依赖的package包/类
private Condition<ConfigurableEnvironment> matchingPropertySource(
final Class<?> propertySourceClass, final String name) {
return new Condition<ConfigurableEnvironment>("has property source") {
@Override
public boolean matches(ConfigurableEnvironment value) {
for (PropertySource<?> source : value.getPropertySources()) {
if (propertySourceClass.isInstance(source)
&& (name == null || name.equals(source.getName()))) {
return true;
}
}
return false;
}
};
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:SpringApplicationTests.java
示例9: findZuulPropertySource
import org.springframework.core.env.ConfigurableEnvironment; //导入方法依赖的package包/类
private MapPropertySource findZuulPropertySource(ConfigurableEnvironment environment) {
for (PropertySource<?> propertySource : environment.getPropertySources()) {
if (propertySource instanceof MapPropertySource) {
for (String key : ((EnumerablePropertySource) propertySource).getPropertyNames()) {
if (key.toLowerCase().startsWith(ZUUL_SERVICE_VERSIONS_ROOT)) {
return (MapPropertySource) propertySource;
}
}
}
}
return null;
}
开发者ID:gorelikov,项目名称:spring-cloud-discovery-version-filter,代码行数:13,代码来源:PropertyTranslatorPostProcessor.java
示例10: propertySourceOrder
import org.springframework.core.env.ConfigurableEnvironment; //导入方法依赖的package包/类
@Test
public void propertySourceOrder() throws Exception {
SimpleNamingContextBuilder.emptyActivatedContextBuilder();
ConfigurableEnvironment env = new StandardServletEnvironment();
MutablePropertySources sources = env.getPropertySources();
assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONFIG_PROPERTY_SOURCE_NAME)), equalTo(0));
assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.SERVLET_CONTEXT_PROPERTY_SOURCE_NAME)), equalTo(1));
assertThat(sources.precedenceOf(PropertySource.named(StandardServletEnvironment.JNDI_PROPERTY_SOURCE_NAME)), equalTo(2));
assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME)), equalTo(3));
assertThat(sources.precedenceOf(PropertySource.named(StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME)), equalTo(4));
assertThat(sources.size(), is(5));
}
示例11: addInlinedPropertiesToEnvironmentWithEmptyProperty
import org.springframework.core.env.ConfigurableEnvironment; //导入方法依赖的package包/类
/**
* @since 4.1.5
*/
@Test
@SuppressWarnings("rawtypes")
public void addInlinedPropertiesToEnvironmentWithEmptyProperty() {
ConfigurableEnvironment environment = new MockEnvironment();
MutablePropertySources propertySources = environment.getPropertySources();
propertySources.remove(MockPropertySource.MOCK_PROPERTIES_PROPERTY_SOURCE_NAME);
assertEquals(0, propertySources.size());
addInlinedPropertiesToEnvironment(environment, new String[] { " " });
assertEquals(1, propertySources.size());
assertEquals(0, ((Map) propertySources.iterator().next().getSource()).size());
}
示例12: addJsonPropertySource
import org.springframework.core.env.ConfigurableEnvironment; //导入方法依赖的package包/类
private void addJsonPropertySource(ConfigurableEnvironment environment,
PropertySource<?> source) {
MutablePropertySources sources = environment.getPropertySources();
String name = findPropertySource(sources);
if (sources.contains(name)) {
sources.addBefore(name, source);
}
else {
sources.addFirst(source);
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:SpringApplicationJsonEnvironmentPostProcessor.java
示例13: flattenPropertySources
import org.springframework.core.env.ConfigurableEnvironment; //导入方法依赖的package包/类
private void flattenPropertySources(PropertySource<?> propertySource,
MutablePropertySources result) {
Object source = propertySource.getSource();
if (source instanceof ConfigurableEnvironment) {
ConfigurableEnvironment environment = (ConfigurableEnvironment) source;
for (PropertySource<?> childSource : environment.getPropertySources()) {
flattenPropertySources(childSource, result);
}
}
else {
result.addLast(propertySource);
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:14,代码来源:ConfigurationPropertiesBindingPostProcessor.java
示例14: convertToStandardEnvironment
import org.springframework.core.env.ConfigurableEnvironment; //导入方法依赖的package包/类
private ConfigurableEnvironment convertToStandardEnvironment(
ConfigurableEnvironment environment) {
StandardEnvironment result = new StandardEnvironment();
removeAllPropertySources(result.getPropertySources());
result.setActiveProfiles(environment.getActiveProfiles());
for (PropertySource<?> propertySource : environment.getPropertySources()) {
if (!SERVLET_ENVIRONMENT_SOURCE_NAMES.contains(propertySource.getName())) {
result.getPropertySources().addLast(propertySource);
}
}
return result;
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:SpringApplication.java
示例15: addEnvironment
import org.springframework.core.env.ConfigurableEnvironment; //导入方法依赖的package包/类
/**
* Add additional (high priority) values to an {@link Environment}. Name-value pairs
* can be specified with colon (":") or equals ("=") separators.
* @param environment the environment to modify
* @param name the property source name
* @param pairs the name:value pairs
*/
public static void addEnvironment(String name, ConfigurableEnvironment environment,
String... pairs) {
MutablePropertySources sources = environment.getPropertySources();
Map<String, Object> map = getOrAdd(sources, name);
for (String pair : pairs) {
int index = getSeparatorIndex(pair);
String key = pair.substring(0, index > 0 ? index : pair.length());
String value = index > 0 ? pair.substring(index + 1) : "";
map.put(key.trim(), value.trim());
}
}