Is there a way to load a class with @ConfigurationProperties without directly using the Spring context? Basically, I want to reuse all the smart logic that Spring does, but for a bean, I manually create an instance outside the Spring life cycle.
I have a bean that loads with joy in Spring (Boot), and I can paste it into another beans service:
@ConfigurationProperties(prefix="my") public class MySettings { String property1; File property2; }
See Spring docco for more information http://docs.spring.io/spring-boot/docs/current-SNAPSHOT/reference/htmlsingle/#boot-features-external-config-command-line-args
But now I need to access this bean from a class created outside of Spring (by Hibernate). The class is created so early in the process of running the application that Spring Boot has not yet made the application context accessible using classic helper search methods or static links made manually.
So instead I want to do something like:
MySettings mySettings = new MySettings(); SpringPropertyLoadingMagicClass loader = new SpringPropertyLoadingMagicClass(); loader.populatePropertyValues(mySettings);
And I have MySettings with all its values loaded from the command line, system properties, app.properties, etc. Is there some class in Spring that does something like this, or is it all too intertwined with the application context?
Obviously, I can just load the properties file myself, but I really want to support Spring loading logic using command line variables (e.g. --my.property1 = xxx) or system variables or application.properties or even a yaml file as well the logic around relaxed type binding and conversion (for example, property2 is a file), so that everything works exactly the same as when used in a Spring context.
Is dream or dream possible?
Thanks for your help!