[英]how to log resource bundle key missing
我正在使用http://java.sun.com/jsp/jstl/fmt標簽庫從Spring配置中設置的Message Resource Bundle輸出消息。 消息解析也可以在Controller中進行。
我想記錄在資源束文件中找不到鍵的情況。
有沒有人知道該怎么做?
Spring使用MessageSource
來檢索消息,因此一種解決方案是編寫自己的MessageSource
來封裝Spring消息源,並覆蓋getMessage
方法以插入日志記錄。
類似於以下內容(未經測試):
<bean id="messageSource" class="com.acme.LoggingMessageSource">
<property name="pathtru">
<bean class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>buttons</value>
<value>labels</value>
</list>
</property>
</bean>
</property>
</bean>
與班級:
public class LoggingMessageSource implements MessageSource {
private MessageSource pathtru;
public String getMessage(String code, Object[] args, String defaultMessage, Locale locale) {
// ...
}
public String getMessage(String code, Object[] args, Locale locale) throws NoSuchMessageException {
// ...
}
public String getMessage(MessageSourceResolvable resolvable, Locale locale) throws NoSuchMessageException {
// ...
}
}
我不知道某些方法是否正在調用其他方法,因此您將不得不嘗試一下。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.