【发布时间】:2011-11-17 13:55:20
【问题描述】:
我正在使用@Value 注释来获取属性,它在 Normal 方法中成功发生,但在 Class 构造函数中没有成功。谁能告诉可能是什么原因?
Class A {
@Value("#{columnProperties['Users.Columns']}")
String columnNames;
A()
{
System.out.println("In Constructor="+columnNames);
}
void show()
{
System.out.println("In Method="+columnNames);
}
}
当我这样做时
A obj=new A();
我得到输出
在构造函数中=null
而obj.show() 给了
在方法=A,B,C
(意思是想要的结果)
我希望在调用构造函数后立即设置值。如果我将字符串声明放在静态或初始化块中,则会出现编译错误。
【问题讨论】:
标签: java spring constructor properties annotations