I haven't seen such question anywhere, so I'm going to ask here about it. I have to make few instances of one object type, the number of how many instances I must instance should be provided from the file .properties. I tried using annotations @Value but it's always giving me
NullPointerException
since the value is null. So for example I have
application.properties
in my resources folder. Let's say the file look like this:
instances.number=5 ...
I use annotation:
@Value("${instances.number}")
private static String lastIndex;
And I want to use it in such way:
psvm {
for(int i = 0; i < Integer.parseInt(lastIndex); i++) {
//creating an instance of object
}
}
So I cannot parse it since it's null value. What should I do to get instances.number value properly?
...