Created
January 27, 2014 06:05
-
-
Save izerui/8643882 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 支持通配符模式获取i18n 配置文件 --> | |
<bean id="messageSource" | |
class="com.izerui.framework.common.application.MultipleMessageSource"> | |
<property name="basenames"> | |
<list> | |
<value>classpath:application/*/messages</value> | |
</list> | |
</property> | |
</bean> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.izerui.framework.common.application; | |
import java.io.IOException; | |
import java.util.Properties; | |
import org.springframework.context.support.ReloadableResourceBundleMessageSource; | |
import org.springframework.core.io.Resource; | |
import org.springframework.core.io.support.PathMatchingResourcePatternResolver; | |
import org.springframework.core.io.support.ResourcePatternResolver; | |
/** | |
* @author izerui.com | |
* @version createtime:2014年1月27日 下午1:06:45 | |
*/ | |
public class MultipleMessageSource extends ReloadableResourceBundleMessageSource { | |
private static final String PROPERTIES_SUFFIX = ".properties"; | |
private ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); | |
@Override | |
protected PropertiesHolder refreshProperties(String filename, PropertiesHolder propHolder) { | |
Properties properties = new Properties(); | |
long lastModified = -1; | |
try { | |
Resource[] resources = resolver.getResources(filename + "*" +PROPERTIES_SUFFIX); | |
for (Resource resource : resources) { | |
String sourcePath = resource.getURI().toString().replace(PROPERTIES_SUFFIX, ""); | |
PropertiesHolder holder = super.refreshProperties(sourcePath, propHolder); | |
properties.putAll(holder.getProperties()); | |
if (lastModified < resource.lastModified()) | |
lastModified = resource.lastModified(); | |
} | |
} catch (IOException ignored) { | |
} | |
return new PropertiesHolder(properties, lastModified); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment