本文整理汇总了Java中org.springframework.core.env.PropertySource类的典型用法代码示例。如果您正苦于以下问题:Java PropertySource类的具体用法?Java PropertySource怎么用?Java PropertySource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PropertySource类属于org.springframework.core.env包,在下文中一共展示了PropertySource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: locate
import org.springframework.core.env.PropertySource; //导入依赖的package包/类
@Override
public PropertySource<?> locate(final Environment environment) {
final AmazonDynamoDBClient amazonDynamoDBClient = getAmazonDynamoDbClient(environment);
createSettingsTable(amazonDynamoDBClient, false);
final ScanRequest scan = new ScanRequest(TABLE_NAME);
LOGGER.debug("Scanning table with request [{}]", scan);
final ScanResult result = amazonDynamoDBClient.scan(scan);
LOGGER.debug("Scanned table with result [{}]", scan);
final Properties props = new Properties();
result.getItems()
.stream()
.map(DynamoDbCloudConfigBootstrapConfiguration::retrieveSetting)
.forEach(p -> props.put(p.getKey(), p.getValue()));
return new PropertiesPropertySource(getClass().getSimpleName(), props);
}
示例2: locate
import org.springframework.core.env.PropertySource; //导入依赖的package包/类
@Override
public PropertySource<?> locate(final Environment environment) {
final Properties props = new Properties();
try {
final JdbcCloudConnection connection = new JdbcCloudConnection(environment);
final DataSource dataSource = Beans.newDataSource(connection);
final JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
final List<Map<String, Object>> rows = jdbcTemplate.queryForList(connection.getSql());
for (final Map row : rows) {
props.put(row.get("name"), row.get("value"));
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return new PropertiesPropertySource(getClass().getSimpleName(), props);
}
示例3: onApplicationEvent
import org.springframework.core.env.PropertySource; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
if (cloud == null) {
return;
}
for (ServiceInfo serviceInfo : cloud.getServiceInfos()) {
if (serviceInfoType.isAssignableFrom(serviceInfo.getClass())) {
PropertySource<?> propertySource = toPropertySource((T) serviceInfo);
event.getEnvironment().getPropertySources().addFirst(propertySource);
}
}
}
开发者ID:pivotal-cf,项目名称:spring-cloud-vault-connector,代码行数:19,代码来源:ServiceInfoPropertySourceAdapter.java
示例4: mergePropertySource
import org.springframework.core.env.PropertySource; //导入依赖的package包/类
protected void mergePropertySource() throws Exception {
if (this.environment != null) {
this.addLast(new PropertySource<Environment>(PropertySourcesPlaceholderConfigurer.ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME, this.environment) {
public String getProperty(String key) {
return this.source.getProperty(key);
}
});
} else {
logger.warn("The injected environment was null!");
}
if (this.locations != null && this.locations.length > 0) {
Properties localProperties = new Properties();
loadProperties(localProperties);
PropertySource<?> localPropertySource = new PropertiesPropertySource(PropertySourcesPlaceholderConfigurer.LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME, localProperties);
if (this.localOverride) {
this.addFirst(localPropertySource);
} else {
this.addLast(localPropertySource);
}
}
}
示例5: addDefaultProperty
import org.springframework.core.env.PropertySource; //导入依赖的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);
}
}
示例6: run
import org.springframework.core.env.PropertySource; //导入依赖的package包/类
@Override
public void run(String... args) throws Exception {
StringBuilder sb = new StringBuilder();
for (String option : args) {
sb.append(" ").append(option);
}
sb = sb.length() == 0 ? sb.append("No Options Specified") : sb;
logger.info(String.format("App launched with following arguments: %s", sb.toString()));
PropertySource<?> ps = new SimpleCommandLinePropertySource(args);
String appUrl = (String) ps.getProperty("appurl");
if (appUrl != null)
logger.info(String.format("Command-line appurl is %s", appUrl));
String applicationPropertyUrl = environment.getProperty("spring.application.url");
logger.info(String.format("Current Spring Social ApplicationUrl is %s", applicationPropertyUrl));
String applicationVersion = environment.getProperty("nixmash.blog.mvc.version");
logger.info(String.format("NixMash MVC Application Version: %s", applicationVersion));
}
示例7: getPropertyNames
import org.springframework.core.env.PropertySource; //导入依赖的package包/类
@Override
public Stream<String> getPropertyNames() throws UnsupportedOperationException {
List<String> names = new LinkedList<>();
if (ConfigurableEnvironment.class.isAssignableFrom(getEnvironment().getClass())) {
MutablePropertySources propertySources = ((ConfigurableEnvironment) getEnvironment()).getPropertySources();
if (propertySources != null) {
Iterator<PropertySource<?>> i = propertySources.iterator();
while (i.hasNext()) {
PropertySource<?> source = i.next();
if (source instanceof EnumerablePropertySource) {
String[] propertyNames = ((EnumerablePropertySource<?>) source).getPropertyNames();
if (propertyNames != null) {
names.addAll(Arrays.asList(propertyNames));
}
}
}
}
}
return names.stream();
}
示例8: locate
import org.springframework.core.env.PropertySource; //导入依赖的package包/类
@Override
public PropertySource<?> locate(Environment environment) {
if (!this.enabled) {
return new MapPropertySource(PROPERTY_SOURCE_NAME, Collections.emptyMap());
}
Map<String, Object> config;
try {
GoogleConfigEnvironment googleConfigEnvironment = getRemoteEnvironment();
Assert.notNull(googleConfigEnvironment, "Configuration not in expected format.");
config = googleConfigEnvironment.getConfig();
}
catch (Exception e) {
String message = String.format("Error loading configuration for %s/%s_%s", this.projectId,
this.name, this.profile);
throw new RuntimeException(message, e);
}
return new MapPropertySource(PROPERTY_SOURCE_NAME, config);
}
示例9: findProps
import org.springframework.core.env.PropertySource; //导入依赖的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;
}
示例10: postProcess
import org.springframework.core.env.PropertySource; //导入依赖的package包/类
public void postProcess(ConfigurableListableBeanFactory beanFactory) {
// 注册 Spring 属性配置
PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer();
MutablePropertySources mutablePropertySources = new MutablePropertySources();
mutablePropertySources.addLast(new PropertySource<String>(Configs.class.getName()) {
@Override
public String getProperty(String name) {
return Configs.getString(name);
}
});
configurer.setPropertySources(mutablePropertySources);
configurer.postProcessBeanFactory(beanFactory);
/*
* 注册 @ConfigValue 处理器. ConfigValueBeanPostProcessor 实现了 ApplicationListener 接口, 不能使用
* beanFactory.addBeanPostProcessor() 来注册实例.
*/
beanFactory.registerSingleton(ConfigValueBeanPostProcessor.class.getName(),
new ConfigValueBeanPostProcessor(beanFactory));
}
示例11: finishAndRelocate
import org.springframework.core.env.PropertySource; //导入依赖的package包/类
public static void finishAndRelocate(MutablePropertySources propertySources) {
String name = APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME;
ConfigurationPropertySources removed = (ConfigurationPropertySources) propertySources
.get(name);
if (removed != null) {
for (PropertySource<?> propertySource : removed.sources) {
if (propertySource instanceof EnumerableCompositePropertySource) {
EnumerableCompositePropertySource composite = (EnumerableCompositePropertySource) propertySource;
for (PropertySource<?> nested : composite.getSource()) {
propertySources.addAfter(name, nested);
name = nested.getName();
}
}
else {
propertySources.addAfter(name, propertySource);
}
}
propertySources.remove(APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME);
}
}
示例12: loadPropertySources
import org.springframework.core.env.PropertySource; //导入依赖的package包/类
private PropertySources loadPropertySources(String[] locations,
boolean mergeDefaultSources) {
try {
PropertySourcesLoader loader = new PropertySourcesLoader();
for (String location : locations) {
Resource resource = this.resourceLoader
.getResource(this.environment.resolvePlaceholders(location));
String[] profiles = this.environment.getActiveProfiles();
for (int i = profiles.length; i-- > 0;) {
String profile = profiles[i];
loader.load(resource, profile);
}
loader.load(resource);
}
MutablePropertySources loaded = loader.getPropertySources();
if (mergeDefaultSources) {
for (PropertySource<?> propertySource : this.propertySources) {
loaded.addLast(propertySource);
}
}
return loaded;
}
catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:27,代码来源:ConfigurationPropertiesBindingPostProcessor.java
示例13: druidDataSource
import org.springframework.core.env.PropertySource; //导入依赖的package包/类
/**
* druid数据源
* @return
*/
@Bean
@ConfigurationProperties(prefix = DB_PREFIX)
public DataSource druidDataSource() {
Properties dbProperties = new Properties();
Map<String, Object> map = new HashMap<>();
for (Iterator<PropertySource<?>> it = ((AbstractEnvironment) environment).getPropertySources().iterator(); it.hasNext();) {
PropertySource<?> propertySource = it.next();
getPropertiesFromSource(propertySource, map);
}
dbProperties.putAll(map);
DruidDataSource dds = null;
try {
dds = (DruidDataSource) DruidDataSourceFactory.createDataSource(dbProperties);
if (null != dds) {
dds.init();
}
} catch (Exception e) {
throw new RuntimeException("load datasource error, dbProperties is :" + dbProperties, e);
}
return dds;
}
示例14: addPropertySource
import org.springframework.core.env.PropertySource; //导入依赖的package包/类
private void addPropertySource(String basename, PropertySource<?> source,
String profile) {
if (source == null) {
return;
}
if (basename == null) {
this.propertySources.addLast(source);
return;
}
EnumerableCompositePropertySource group = getGeneric(basename);
group.add(source);
logger.trace("Adding PropertySource: " + source + " in group: " + basename);
if (this.propertySources.contains(group.getName())) {
this.propertySources.replace(group.getName(), group);
}
else {
this.propertySources.addFirst(group);
}
}
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:24,代码来源:PropertySourcesLoader.java
示例15: testPlaceholdersErrorInNonEnumerable
import org.springframework.core.env.PropertySource; //导入依赖的package包/类
@Test
public void testPlaceholdersErrorInNonEnumerable() {
TestBean target = new TestBean();
DataBinder binder = new DataBinder(target);
this.propertySources.addFirst(new PropertySource<Object>("application", "STUFF") {
@Override
public Object getProperty(String name) {
return new Object();
}
});
binder.bind(new PropertySourcesPropertyValues(this.propertySources,
(Collection<String>) null, Collections.singleton("name")));
assertThat(target.getName()).isNull();
}