Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

classpath wildcard in @PropertySource

I am using Spring Java config to create my bean. But this bean is common to 2 applications. Both have one property file abc.properties but with different classpath locations. When i put explicit classpath like

@PropertySource("classpath:/app1/abc.properties")

then it works but when i try to use wildcard like

@PropertySource("classpath:/**/abc.properties")

then it doesn't work. I try many combinations of wildcard but it still not working. Is wildcard works in @ProeprtySource Is there any other way to read to property in classed marked with @Configurations.

like image 254
dmay Avatar asked Jan 17 '13 23:01

dmay


1 Answers

Addidtionally to dmay workaround:

Since Spring 3.1 PropertySourcesPlaceholderConfigurer should be used preferentially over PropertyPlaceholderConfigurer and the bean should be static.

@Configuration
public class PropertiesConfig {

  @Bean
  public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() {
    PropertySourcesPlaceholderConfigurer propertyConfigurer = new PropertySourcesPlaceholderConfigurer();
    propertyConfigurer.setLocations(new PathMatchingResourcePatternResolver().getResources("classpath:/**/abc.properties"));
    return propertyConfigurer;
  }

}
like image 163
Michal Z m u d a Avatar answered Sep 28 '22 07:09

Michal Z m u d a