当前位置: 首页>>代码示例>>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;未经允许,请勿转载。