可以這樣做嗎?目前它是這樣做的:通過Spring Framework中的註釋獲取來自resourceBundle的本地化消息
<bean id="resource" class="org.springframework.context.support.ResourceBundleMessageSource">
<property name="basenames">
<list>
<value>content.Language</value>
</list>
</property>
</bean>
@Autowired
protected MessageSource resource;
protected String getMessage(String code, Object[] object, Locale locale) {
return resource.getMessage(code, object, locale);
}
有沒有辦法讓它像通過@Value註解獲取屬性?
<util:properties id="generals" location="classpath:portlet.properties" />
@Value("#{generals['supported.lang.codes']}")
public String langCodes;
因爲不必調用該方法通常是好的,但例如當單元測試,這是痛苦......那麼在某些情況下,的webdriver的PageObject模式,其中對象沒有任何初始化,這將是非常有幫助的
我也想知道爲什麼這個功能不存在,在3.1和可能3。2沒有這樣的歌曲要實施。 – lisak 2011-06-05 23:54:36
Is:supported.lang.codes屬性文件的鍵值對,還是應該是程序計算所有支持的語言的值? – Ralph 2011-06-06 10:24:35
這只是屬性文件的一個關鍵值。這實際上是獲取屬性的非常方便的方式。我希望Spring能夠像本地化一樣... @Localize(「#{langCode ['some.error.message]}」) – lisak 2011-06-06 10:28:12