Nig*_*olf 34 java spring dependency-injection properties properties-file
关于最终属性的属性文件中Spring注入的简单问题.
我有一个属性文件,我想存储一个文件路径.通常当我使用属性文件时,我使用类似这样的东西设置类属性:
private @Value("#{someProps['prop.field']}") String someAttrib ;
Run Code Online (Sandbox Code Playgroud)
然后在我的spring.xml我会有类似的东西:
<util:properties id="someProps"
location="classpath:/META-INF/properties/somePropFile.properties" />
Run Code Online (Sandbox Code Playgroud)
这很好用,很简单,使代码更好,更整洁.但我不确定在尝试将属性值注入最终类属性时使用的最佳模式是什么?
显然是这样的:
private static final @Value("#{fileProps['dict.english']}") String DICT_PATH;
Run Code Online (Sandbox Code Playgroud)
不管用.还有另外一种方法吗?
干杯!
Aus*_*ole 10
如果您正在寻找一个例子:
public class Test {
private final String value;
public Test(@Value("${some.value}") String value){
this.value=value;
System.out.println(this.value);
}
}
Run Code Online (Sandbox Code Playgroud)