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;
}
java类org.springframework.context.annotation.PropertySource的实例源码
WebMvcApplicationConfig.java 文件源码
项目:backbone
阅读 35
收藏 0
点赞 0
评论 0
ConfigurationBuilder.java 文件源码
项目:chassis
阅读 29
收藏 0
点赞 0
评论 0
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);
}
ConfigFileApplicationListenerTests.java 文件源码
项目:https-github.com-g0t4-jenkins2-course-spring-boot
阅读 27
收藏 0
点赞 0
评论 0
@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]");
}
JdbcComponentConfig.java 文件源码
项目:nbone
阅读 35
收藏 0
点赞 0
评论 0
@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);
}
ConfigFileApplicationListenerTests.java 文件源码
项目:spring-boot-concourse
阅读 29
收藏 0
点赞 0
评论 0
@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]");
}
ConfigFileEnvironmentPostProcessorTests.java 文件源码
项目:contestparser
阅读 32
收藏 0
点赞 0
评论 0
@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]"));
}