Menu

HowToDependentValue

Sahits GmbH

HowTo use @DependentValue

The annotation @DependentValue works in a very similar way as @Value at least in it's effects. However there is a bit more to it. The backing value is tretrieved through an IPropertyInitializer which reads in the property file that holds the values. However in the property file there are multiple values defined for each key. They are distinguished by an additional segment of the key and this additional segment is defined through the implementation of IPropertyInitializer, thus creating the complete key name.
These values however are not automatically replaced in the bean as with @Value, they require to be initialized through ch.sahits.game.openpatrician.util.spring.DependentPropertyInitializer which is also wired into the bean and called in a post-construct method:

propertyInitializer.initializeAnnotatedFields(this);

This is used to inject values that are dependent on the difficulty. The IPropertyInitializer is setup with the suffix of the game difficulty and thereby the appropriate values can be loaded.


Related

Wiki: HowToDev

MongoDB Logo MongoDB