This is not a problem with spring as much as with a conflict between what you want and what Java allows. You cannot defer the assignment of a static final property. It must be installed when the class is loaded. Therefore, by the time spring can be entered, it is too late.
If you donβt have to be final, you can open some options.
Another possibility is that it may be possible to create an aspect when intercepting access to a property and return the value you want, not the stored value. You can then enter the desired value into the aspect.
I have never done this specifically with static properties, but I assume this is possible. It is not possible to use constant fields (static end fields bound to a constant object or primitive value) like JoinPoint, since java requires them to be inline, but since you are pointing to an object other than String, I think using the aspect can work.
To make sure that spring introduces into your aspect, be sure to let spring know about it through the following:
<bean id="someId" class="com.yourdomain.YourAspect" factory-method="aspectOf"/>
source share