I've just tried this, and it still doesn't work for me.
I changed your TestBean slightly, as I was missing a couple of interfaces, but not so as to affect the test, I don't think.
Used the following to test it:
Code:
public class Runner {
public static void main(String[] args) {
Runner runner = new Runner();
runner.testPropertyPlaceholderConfigurerWithInnerBeansInConstructorArgs();
}
public void testPropertyPlaceholderConfigurerWithInnerBeansInConstructorArgs() {
ClassPathXmlApplicationContext ctx =
new ClassPathXmlApplicationContext("test.xml");
ctx.refresh();
TestBean tb = (TestBean)ctx.getBean("testBean");
TestBean spouse = tb.getSpouse();
//assertEquals(98, spouse.getAge());
System.out.println("spouse.getAge gives " + spouse.getAge());
}
}
I got the following result:
Code:
/usr/j2sdk1.4.2_05/bin/java -Dfile.encoding=US-ASCII -classpath /usr/j2sdk1.4.2_05/jre/lib/sunrsasign.jar:/usr/j2sdk1.4.2_05/jre/lib/jce.jar:/usr/j2sdk1.4.2_05/jre/lib/charsets.jar:/usr/j2sdk1.4.2_05/jre/lib/plugin.jar:/usr/j2sdk1.4.2_05/jre/lib/rt.jar:/usr/j2sdk1.4.2_05/jre/lib/jsse.jar:/usr/j2sdk1.4.2_05/jre/lib/ext/sunjce_provider.jar:/usr/j2sdk1.4.2_05/jre/lib/ext/dnsns.jar:/usr/j2sdk1.4.2_05/jre/lib/ext/ldapsec.jar:/usr/j2sdk1.4.2_05/jre/lib/ext/localedata.jar:/var/home/dp01/configtest:/user1/spring-framework-1.0.2/dist/spring.jar:/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-attributes-api-SNAPSHOT.jar:/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-attributes-compiler-SNAPSHOT.jar:/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-beanutils.jar:/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-collections.jar:/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-dbcp.jar:/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-digester.jar:/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-discovery.jar:/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-fileupload.jar:/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-lang.jar:/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-logging.jar:/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-pool.jar:/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-validator.jar org.springframework.beans.Runner
Sep 1, 2004 8:54:50 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [test.xml]
Sep 1, 2004 8:54:51 AM org.springframework.context.support.AbstractXmlApplicationContext refreshBeanFactory
INFO: Bean factory for application context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=605645]: org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [testBean,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer]; Root of BeanFactory hierarchy
Sep 1, 2004 8:54:51 AM org.springframework.context.support.AbstractApplicationContext refresh
INFO: 2 beans defined in ApplicationContext [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=605645]
Sep 1, 2004 8:54:51 AM org.springframework.beans.factory.support.AbstractBeanFactory getBean
INFO: Creating shared instance of singleton bean 'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer'
Sep 1, 2004 8:54:51 AM org.springframework.context.support.AbstractApplicationContext initMessageSource
INFO: No MessageSource found for context [org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=605645]: using empty StaticMessageSource
Sep 1, 2004 8:54:51 AM org.springframework.context.support.AbstractApplicationContext refreshListeners
INFO: Refreshing listeners
Sep 1, 2004 8:54:51 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in factory [org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [testBean,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer]; Root of BeanFactory hierarchy]
Sep 1, 2004 8:54:51 AM org.springframework.beans.factory.support.AbstractBeanFactory getBean
INFO: Creating shared instance of singleton bean 'testBean'
Sep 1, 2004 8:54:51 AM org.springframework.beans.factory.support.AbstractBeanFactory destroySingletons
INFO: Destroying singletons in factory {org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans [testBean,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer]; Root of BeanFactory hierarchy}
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.beans.TestBean' defined in class path resource [test.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [int] for property 'age'; nested exception is java.lang.NumberFormatException: For input string: "${age}"]
PropertyAccessExceptionsException (1 errors)
org.springframework.beans.TypeMismatchException: Failed to convert property value of type [java.lang.String] to required type [int] for property 'age'; nested exception is java.lang.NumberFormatException: For input string: "${age}"
java.lang.NumberFormatException: For input string: "${age}"
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:468)
at java.lang.Integer.valueOf(Integer.java:574)
at sun.beans.editors.IntEditor.setAsText(IntEditor.java:21)
at org.springframework.beans.BeanWrapperImpl.doTypeConversionIfNecessary(BeanWrapperImpl.java:828)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:637)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:568)
at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:685)
at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:712)
at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:701)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:626)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:467)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:232)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveInnerBeanDefinition(AbstractAutowireCapableBeanFactory.java:702)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveValueIfNecessary(AbstractAutowireCapableBeanFactory.java:663)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:307)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:177)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:159)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:183)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:268)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:58)
at org.springframework.beans.Runner.testPropertyPlaceholderConfigurerWithInnerBeansInConstructorArgs(Runner.java:20)
at org.springframework.beans.Runner.main(Runner.java:16)
Process finished with exit code 1