I'm using @Value
annotation to fetch properties & it is happening successfully in Normal method but not in Class constructor.Can anyone tell what may be the reason?
Class A {
@Value("#{columnProperties['Users.Columns']}")
String columnNames;
A()
{
System.out.println("In Constructor="+columnNames);
}
void show()
{
System.out.println("In Method="+columnNames);
}
}
when i do
A obj=new A();
i get the output
In Constructor=null
and obj.show()
gives
In Method=A,B,C
(that means desired result)
I want values to be set as soon as constructor is called.I'm getting compilation error if i put the String declaration in static or initialize block.