2013-10-17 69 views
0

我有通過Spring配置的ReloadableResourceBundleMessageSource。一切工作正常。我想在資源包中添加更多的字符串,但是,我看到了UnknownFormatConversionException。Spring ReloadableResourceBundleMessageSource:查看UnknownFormatConversionException

我所要的輸出是:
Following filesystems are below threshold level (25%):/db

我的資源包已經
filesystemsBelowThreshold=Following filesystems are below threshold level {0}%:{1}

然而,上述格式不工作,它與
UnknownFormatConversionException: Conversion = ')'.
抱怨如果我刪除輪大括號,它抱怨着
UnknownFormatConversionException: Conversion = ':'.
我試着用另一種逃避%%,爲
filesystemsBelowThreshold=Following filesystems are below threshold level {0}%%:{1},不過,我得到UnknownFormatConversionException: Conversion = ':'.

任何想法,我該如何解決這個問題?

+0

嘗試轉義:由\: –

+0

我認爲=和:屬性文件中的特殊字符 –

+0

@SRT_KP:這是行不通的。我更改爲'filesystemsBelowThreshold =以下文件系統低於閾值級別{0}%\:{1}',但是我仍然得到相同的錯誤,即'UnknownFormatConversionException:Conversion =':''。 – devang

回答

0

下面是代碼

<bean id="messageSource" 
     class="org.springframework.context.support.ReloadableResourceBundleMessageSource"> 
     <property name="basename" value="classpath:messages" /> 
     <property name="defaultEncoding" value="UTF-8" /> 
    </bean> 

而且屬性文件

filesystemsBelowThreshold=Following filesystems are below threshold level {0}%:{1} 

而且測試

 Object[] obj = {25, "/db"}; 
     String str= message.getMessage("filesystemsBelowThreshold", obj, null); 
     System.out.println(str); 

和輸出

以下文件系統低於閾值水平25%:/ db

相關問題