I am designing a plugin system for our web based application using Spring framework. Plugins are jars on classpath. So I am able to get sources such as jsp, see below
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] pages = resolver.getResources("classpath*:jsp/*jsp");
So far so good. But I have a problem with the messageSource. It seems to me that ReloadableResourceBundleMessageSource#setBasename does NOT support multiple class path via the “classpath*:” If I use just “classpath:”, I get the messageSource just only from one plugin.
Does anyone have an idea how to register messageSources from all plugins? Does exist such an implementation of MessageSource?
The issue here is not with multiple classpaths or classloaders, but with how many resources the code will try and load for a given path.
The
classpath*syntax is a Spring mechanism, one which allows code to load multiple resources for a given path. Very handy. However,ResourceBundleMessageSourceuses the standardjava.util.ResourceBundleto load the resources, and this is a much simpler, dumber mechanism, which will load the first resource for a given path, and ignore everything else.I don’t really have an easy fix for you. I think you’re going to have to ditch
ResourceBundleMessageSourceand write a custom implementation ofMessageSource(most likely by subclassingAbstractMessageSource) which usesPathMatchingResourcePatternResolverto locate the various resources and expose them via theMessageSourceinterface.ResourceBundleisn’t going to be much help.