Strange behavior with Java-centric configuration of PropertyPlaceholderConfigurer
Consider the following use of a combined PropertySourcesPlaceholderConfigurer and a legacy PropertyPlaceholderConfigurer defined in xml:
Code:
@Configuration
@ImportResource("classpath:beans.spring.xml")
public class MyConfiguration {
@Bean
public static PropertySourcesPlaceholderConfigurer pspc () {
return new PropertySourcesPlaceholderConfigurer();
}
}
Code:
<bean id="test.propertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="ignoreResourceNotFound" value="true" />
<property name="locations">
<set>
<value>classpath:foo.properties</value>
</set>
</property>
</bean>
<bean id="test.foo" class="Foo">
<property name="foo" value="${foo}"/>
</bean>
If I construct a new AnnotationConfigApplicationContext(MyConfiguration .class) I get the following error:
org.springframework.beans.factory.BeanDefinitionSt oreException: Invalid bean definition with name 'test.foo' defined in class path resource [beans.spring.xml]: Could not resolve placeholder 'foo' in string value [${foo}]
However, If I modify MyConfiguration to use a static inner class for the ImportResource, it works:
Code:
@Configuration
public class MyConfiguration
{
@Configuration
@ImportResource("classpath:beans.spring.xml")
static class InnerConfiguration {}
@Bean
public static PropertySourcesPlaceholderConfigurer pspc () {
return new PropertySourcesPlaceholderConfigurer();
}
}
It also works if I remove the pspc bean, but I need that for further work. I don't understand this behavior, and I'm concerned about doing further work with a mixture of xml and java configuration. I'm using spring 3.1.2.
jeff