Spring Framework

annotations

Given is the following scenario:
 
  • The fortune service reads the fortunes from a file.
  • The fortune service loads the fortunes into an array 
    => String[] data= {a,b,c,d,e};
 
Why is the array always null and how to solve it?
 

Spring creates an instance of the class first and sets the properties at the very end, so that the array gets initialized without any values.
 
We can fill the array with values with a helper method having the
@PostConstruct annotation
 

Diskussion