Reputation: 54584
I'm in the process of converting our XML- to a Java-based Spring 3 configuration, and couldn't find a way to "translate" this bean which uses wildcards for resource paths:
<bean id="messageSource" class="MyResourceBundleMessageSource">
<property name="resources" value="classpath*:messages/*.properties" />
</bean>
The corresponding class looks like:
public class MyResourceBundleMessageSource
extends org.springframework.context.support.ResourceBundleMessageSource {
...
public void setResources(org.springframework.core.io.Resource... resources)
throws java.io.IOException { ... }
...
}
Enumerating all the files "manually" is no option, as this is a multi-module project with quite a few files, and I would like to avoid changing the bean class as well (as it is actually located in a common library).
Upvotes: 4
Views: 3679
Reputation: 54584
Following Sotirios Delimanolis' advice, I got it working:
@Bean
public MyResourceBundleMessageSource messageSource() throws IOException {
MyResourceBundleMessageSource messageSource = new MyResourceBundleMessageSource();
messageSource.setResources(new PathMatchingResourcePatternResolver().getResources("classpath*:messages/*.properties"));
return messageSource;
}
Upvotes: 8