當前位置: 首頁>>代碼示例>>Java>>正文


Java PropertySource類代碼示例

本文整理匯總了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);
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:18,代碼來源:DynamoDbCloudConfigBootstrapConfiguration.java

示例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);
}
 
開發者ID:mrluo735,項目名稱:cas-5.1.0,代碼行數:18,代碼來源:JdbcCloudConfigBootstrapConfiguration.java

示例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);
		}
	}
}
 
開發者ID:penggle,項目名稱:xproject,代碼行數:22,代碼來源:GlobalPropertySources.java

示例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);
    }
}
 
開發者ID:micrometer-metrics,項目名稱:micrometer,代碼行數:18,代碼來源:MetricsEnvironmentPostProcessor.java

示例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));

}
 
開發者ID:mintster,項目名稱:nixmash-blog,代碼行數:24,代碼來源:MvcLoader.java

示例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();
}
 
開發者ID:holon-platform,項目名稱:holon-core,代碼行數:21,代碼來源:DefaultEnvironmentConfigPropertyProvider.java

示例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);
}
 
開發者ID:spring-cloud,項目名稱:spring-cloud-gcp,代碼行數:19,代碼來源:GoogleConfigPropertySourceLocator.java

示例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;
}
 
開發者ID:taboola,項目名稱:taboola-cronyx,代碼行數:18,代碼來源:EnvironmentUtil.java

示例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));
}
 
開發者ID:kevin70,項目名稱:setaria,代碼行數:21,代碼來源:ConfigValueBeanFactoryPostProcessor.java

示例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);
	}
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:21,代碼來源:ConfigFileApplicationListener.java

示例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;
}
 
開發者ID:qjx378,項目名稱:wenku,代碼行數:28,代碼來源:DruidConfiguration.java

示例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();
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:17,代碼來源:PropertySourcesPropertyValuesTests.java


注:本文中的org.springframework.core.env.PropertySource類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。