Does Spring MessageSource Support Multiple Class Path?

后端 未结 6 2223
终归单人心
终归单人心 2020-12-05 08:08

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

<
6条回答
  •  悲哀的现实
    2020-12-05 08:38

    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, ResourceBundleMessageSource uses the standard java.util.ResourceBundle to 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 ResourceBundleMessageSource and write a custom implementation of MessageSource (most likely by subclassing AbstractMessageSource) which uses PathMatchingResourcePatternResolver to locate the various resources and expose them via the MessageSource interface. ResourceBundle isn't going to be much help.

提交回复
热议问题