Suppose I have an AppProperties POJO annotated with @ConfigurationProperties("app"). It contains different app properties which I usually use to configure my beans in @Configuration classes.
@EnableConfigurationProperties(AppProperties.class) makes it available for @Autowiring, this is very convenient for Java-configuration.
But one part of my app's context is configured using old-fashined XML-confiuration. I would like to know how can I access @ConfigurationProperties AppProperties bean in XML configuration? If only @EnableConfigurationProperties provided me an ability to give a name, I could probably use SpEL in XML like this: #{appProperties.requiredProp} (I would really like to achieve it).
Unfortunately I do not see a way to provide the name and my attempt to use suggested appProperties name fails with:
SpelEvaluationException: EL1008E: Property or field 'appProperties' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public or not valid?
I've seen in debugger that the bean is actually called app-my.package.AppProperties which is not obvious and never stated explicitly.
In JavaDoc for @EnableConfigurationProperties I noticed the following:
@ConfigurationPropertiesbeans can be registered in the standard way (for example using@Beanmethods) or, for convenience, can be specified directly on this (@EnableConfigurationProperties) annotation.
Does this mean I can somehow get a named instance of AppProperties with values injected from application.properties using either @Bean method in Java or <bean/> in XML?
Of course, I could autowire the whole AppProperties to the class configured with XML, but I do not think it is a good design solution, because am only interested in a single String property from AppProperties. Probably I should not try to use this "type-safe" properties manner in XML and just stick to old way: using ${}-resolution, but I feel like I am missing something in the @ConfigurationProperties concept so please let me know.