当我在config服务器中测试以下url时,它完美地工作并返回纯文本文件:http://localhost:8888/icullen-webapp/default/master/messages_en_US.properties
但是当我在配置客户端中使用时,加载我的页面需要很长时间,因为我在同一页面中有太多翻译 . 代码从config repo中找到翻译,但是对于每个翻译,它都会调用服务器,因此它很慢 .
在下面找到我的代码:
<bean id="messageSource"
class="com.icullen.site.utils.TolerantReloadableResourceBundleMessageSource">
<property name="basenames" value="http://localhost:8888/icullen-webapp/default/master/messages" />
<property name="defaultEncoding" value="UTF-8" />
<property name="cacheSeconds">
<value>5</value>
</property>
</bean>
public class TolerantReloadableResourceBundleMessageSource extends
ReloadableResourceBundleMessageSource {
private static final Logger logger = LoggerFactory.getLogger(TolerantReloadableResourceBundleMessageSource.class);
@Override
protected String getMessageInternal(String code, Object[] args,
Locale locale) {
String messageInternal = super.getMessageInternal(code, args, locale);
if(messageInternal == null){
logger.warn("No translation for : {}", code);
}
return messageInternal != null ? messageInternal : "?" + code + "?";
}
}
使用像这样的spring消息在jsp中调用翻译
<spring:message htmlEscape="true" code="category.${region.name}"/>
我究竟做错了什么 ?我该怎么做才能快速加载页面 . 我们被卡住了,请帮忙 .
1 回答
我找到了解决方案:这是我的缓存 Value . 我不得不把缓存放到-1,即 - 永远缓存 . 当我更改我的属性文件时,我调用了一个手动刷新缓存的控制器 .
}