I use the @Value annotation to retrieve properties, and this succeeds in the regular method, but not in the class constructor. Can someone say what could 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 a conclusion
In Constructor = null
and obj.show() gives
In method = A, B, C
(this means the desired result)
I want the values to be set as soon as the constructor is called. I get a compilation error if I put a String declaration in a static or initialization block.
source share