Question

Right now I am reading properties file in spring as

<bean id="messageSource"
    class="org.springframework.context.support.ResourceBundleMessageSource">
    <property name="basename" value="customer/messages" />
</bean>

Here I am specifying that read messages.properties in customer directory. But what I want to do is to specify a directory and ask spring to read all properties file present in that directory. How can I achieve that?

I tried value="customer/*" but it doesn't work.

Was it helpful?

Solution 2

OTHER TIPS

Using <context:property-placeholder> is more recommended as:

<context:property-placeholder 
    locations="classpath:path/to/customer/*.properties" />

You can also do this using Spring 3.1+ Java Config with:

@Bean
public static PropertyPlaceholderConfigurer properties(){
  PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
  Resource[] resources = new ClassPathResource[ ]
    { new ClassPathResource( "path/to/customer/*.properties" ) };
  ppc.setLocations( resources );
  ppc.setIgnoreUnresolvablePlaceholders( true );
  return ppc;
}

You may need to tailor the type of resource to load properties from:

To use a property, you can use Environment abstraction. It can be injected and used to retrieve property values at runtime.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top