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=fooconfiguration_en.properties
my.key=bazprintMe在FooBar实例上的结果将打印字符串:
my.key = baz如果user.language系统属性设置为en
发布于 2014-06-25 02:37:25
嗨,您可以尝试用@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()));
}https://stackoverflow.com/questions/24156688
复制相似问题