[英]ResourceBundle as PropertySource in spring
PropertySource 文檔演示了使用@PropertySource
將屬性文件鍵/值對注入spring上下文。
我想知道是否可以對資源包做同樣的事情。 例如:
@Configuration
@PropertySource("classpath:configuration")
public class FooBar {
@Value("${my.key}")
private String someValue;
public void printMe(){
System.out.println("my.key = " + someValue);
}
}
configuration.properties
my.key=foo
configuration_en.properties
my.key=baz
FooBar實例上的printMe結果將打印字符串:
my.key = baz
如果將user.language
系統屬性設置為en
嗨,您可以嘗試使用@Resource注釋消息源
@Resource(name = "<id of your configured message source>")
protected MessageSource resources;
public void printMe() {
System.out.println(resources.getMessage("my.key", null, LocaleContextHolder.getLocale()));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.