How do I use wildcards when searching for resources in a Java based spring configuration?

I'm converting XML to a Java based spring 3 configuration, and I can't find a way to "translate" beans that use wildcards as 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 { ... }
      ... 
    }

There is no choice to "manually" enumerate all files, because this is a multi module project with a considerable number of files. I also want to avoid changing the bean class (because it is actually located in the Public Library)

Solution

As suggested by Sotirios delimanolis, I got its work:

@Bean
public MyResourceBundleMessageSource messageSource() throws IOException {
    MyResourceBundleMessageSource messageSource = new MyResourceBundleMessageSource();
    messageSource.setResources(new PathMatchingResourcePatternResolver().getResources("classpath*:messages/*.properties"));
    return messageSource;
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>