1
使用值注释读我有一个属性文件说如下:更新值在春季
apple=1
mango=2
banana=3
pineapple=4
我现在用在Java程序中值注释访问值。我有一个方法在我的类中计算一个值,我想用方法返回的值更新属性文件中的apple属性。
public class test {
@Value("${apple}")
private int apple;
public void testMethod() {
int new_val = 0;
if (apple > 0)
new_val = 300;
else
new_val = 200;
// now i want to update the value of apple in the file to new_val,(apple = new_val) other attributes should remain unchanged.
}
}
有人可以让我知道如何更新属性文件中的值。在这个例子中,我希望我的属性文件变为
apple=300
mango=2
banana=3
pineapple=4
[在运行时与@Value注释更新场]的可能的复制(https://stackoverflow.com/questions/16478679/update-field-annotated-with-value-in-runtime) –