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


Java PropertySource類代碼示例

本文整理匯總了Java中org.springframework.context.annotation.PropertySource的典型用法代碼示例。如果您正苦於以下問題:Java PropertySource類的具體用法?Java PropertySource怎麽用?Java PropertySource使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PropertySource類屬於org.springframework.context.annotation包,在下文中一共展示了PropertySource類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getPropsResources

import org.springframework.context.annotation.PropertySource; //導入依賴的package包/類
protected Resource[] getPropsResources(ResourceLoader resourceLoader) {
    PropertySource sourceAnnotation = WebMvcApplicationConfig.class.getAnnotation(PropertySource.class);
    String[] props = sourceAnnotation.value();
    if (props.length > 0) {
        List<Resource> list = new ArrayList<Resource>(1);
        for (String prop : props) {
            Resource resource = resourceLoader.getResource(prop);
            if (resource.exists())
                list.add(resource);
        }
        if (!CollectionUtils.isEmpty(list)) {
            Resource[] resources = new Resource[list.size()];
            list.toArray(resources);
            //print log
            printLog(Global.BEAN_NAME_ROOT_PROPS, resources);

            return resources;
        }
   }
    return null;
}
 
開發者ID:cyanqueen,項目名稱:backbone,代碼行數:22,代碼來源:WebMvcApplicationConfig.java

示例2: initModuleConfiguration

import org.springframework.context.annotation.PropertySource; //導入依賴的package包/類
private void initModuleConfiguration() {
    if (!scanModuleConfigurations) {
        this.moduleDefaultConfiguration = new ConcurrentMapConfiguration();
        return;
    }
    HashMap<String, Object> base = new HashMap<>();
    Set<Class<?>> types = reflections
            .getTypesAnnotatedWith(PropertySource.class);
    for (Class<?> type : types) {
        PropertySource propertySource = type
                .getAnnotation(PropertySource.class);
        String[] propertiesFiles = propertySource.value();
        for (String propertyFile : propertiesFiles) {
            Properties properties = new Properties();
            try (InputStream is = resourceLoader.getResource(SystemPropertyUtils.resolvePlaceholders(propertyFile))
                    .getInputStream()) {
                properties.load(is);
                LOGGER.debug("Initializing module properties from path " + propertyFile);
            } catch (Exception e) {
                BootstrapException.resourceLoadingFailed(propertyFile, e);
            }
            join(base, properties, propertyFile, propertiesFiles);
        }
    }
    this.moduleDefaultConfiguration = new ConcurrentMapConfiguration(base);
}
 
開發者ID:Kixeye,項目名稱:chassis,代碼行數:27,代碼來源:ConfigurationBuilder.java

示例3: yamlSetsProfiles

import org.springframework.context.annotation.PropertySource; //導入依賴的package包/類
@Test
public void yamlSetsProfiles() throws Exception {
	this.initializer.setSearchNames("testsetprofiles");
	this.initializer.postProcessEnvironment(this.environment, this.application);
	assertThat(this.environment.getActiveProfiles()).containsExactly("dev");
	String property = this.environment.getProperty("my.property");
	assertThat(this.environment.getActiveProfiles()).contains("dev");
	assertThat(property).isEqualTo("fromdevprofile");
	ConfigurationPropertySources propertySource = (ConfigurationPropertySources) this.environment
			.getPropertySources()
			.get(ConfigFileApplicationListener.APPLICATION_CONFIGURATION_PROPERTY_SOURCE_NAME);
	Collection<org.springframework.core.env.PropertySource<?>> sources = propertySource
			.getSource();
	assertThat(sources).hasSize(2);
	List<String> names = new ArrayList<String>();
	for (org.springframework.core.env.PropertySource<?> source : sources) {
		if (source instanceof EnumerableCompositePropertySource) {
			for (org.springframework.core.env.PropertySource<?> nested : ((EnumerableCompositePropertySource) source)
					.getSource()) {
				names.add(nested.getName());
			}
		}
		else {
			names.add(source.getName());
		}
	}
	assertThat(names).contains(
			"applicationConfig: [classpath:/testsetprofiles.yml]#dev",
			"applicationConfig: [classpath:/testsetprofiles.yml]");
}
 
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:31,代碼來源:ConfigFileApplicationListenerTests.java

示例4: afterPropertiesSet

import org.springframework.context.annotation.PropertySource; //導入依賴的package包/類
@Override
public void afterPropertiesSet() throws Exception {
	logger.info("========================================================================");
	logger.info("nbone JdbcComponent starting ....");
	logger.info("========================================================================");
	org.springframework.core.env.PropertySource<?> ps =  env.getPropertySources().get("jdbcComponentConig");
	if(ps != null){
		config = (Properties) ps.getSource();
	}
	String name  = env.getProperty("nbone.name");
	String dataSourceName = env.getProperty("nbone.datasource.name");
	System.out.println("========================="+name);
	System.out.println("========================="+dataSourceName);
}
 
開發者ID:thinking-github,項目名稱:nbone,代碼行數:15,代碼來源:JdbcComponentConfig.java

示例5: yamlSetsProfiles

import org.springframework.context.annotation.PropertySource; //導入依賴的package包/類
@Test
public void yamlSetsProfiles() throws Exception {
	this.initializer.setSearchNames("testsetprofiles");
	this.initializer.postProcessEnvironment(this.environment, this.application);
	assertEquals("dev", StringUtils
			.arrayToCommaDelimitedString(this.environment.getActiveProfiles()));
	String property = this.environment.getProperty("my.property");
	assertThat(Arrays.asList(this.environment.getActiveProfiles()), contains("dev"));
	assertThat(property, equalTo("fromdevprofile"));
	ConfigurationPropertySources propertySource = (ConfigurationPropertySources) this.environment
			.getPropertySources().get("applicationConfigurationProperties");
	Collection<org.springframework.core.env.PropertySource<?>> sources = propertySource
			.getSource();
	assertEquals(2, sources.size());
	List<String> names = new ArrayList<String>();
	for (org.springframework.core.env.PropertySource<?> source : sources) {
		if (source instanceof EnumerableCompositePropertySource) {
			for (org.springframework.core.env.PropertySource<?> nested : ((EnumerableCompositePropertySource) source)
					.getSource()) {
				names.add(nested.getName());
			}
		}
		else {
			names.add(source.getName());
		}
	}
	assertThat(names,
			contains("applicationConfig: [classpath:/testsetprofiles.yml]#dev",
					"applicationConfig: [classpath:/testsetprofiles.yml]"));
}
 
開發者ID:Nephilim84,項目名稱:contestparser,代碼行數:31,代碼來源:ConfigFileEnvironmentPostProcessorTests.java


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