Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: PropertyPlaceholderConfigurer not working with inner bean?

  1. #1
    Join Date
    Aug 2004
    Location
    Carlisle, UK
    Posts
    184

    Default PropertyPlaceholderConfigurer not working with inner bean?

    I currently using Spring ver. 1.0.2
    I am using PropertyPlaceholderConfigurer successfully in a number of places, but have found that it doesn't seem to work on an inner bean.

    Thus, the following works fine:

    Code:
        <bean id="ifxds" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiName"><value>$&#123;informixJndiName&#125;</value></property>
        </bean>
    
        <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
            <constructor-arg>
                <ref bean="ifxds"/>
            </constructor-arg>
        </bean>
    But the following doesn't:

    Code:
            <bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
                <constructor-arg>
                    <bean class="org.springframework.jndi.JndiObjectFactoryBean">
                        <property name="jndiName"><value>$&#123;informixJndiName&#125;</value></property>
                    </bean>
                </constructor-arg>
            </bean>
    giving the following error:

    Code:
    org.springframework.beans.factory.BeanCreationException&#58; Error creating bean with name 'org.springframework.jndi.JndiObjectFactoryBean' defined in resource/WEB-INF/config/wo_bus_config.xml&#93; of ServletContext&#58; Initialization of bean failed; nested exception is javax.naming.NameNotFoundException&#58;  $&#123;informixJndiName&#125; not bound javax.naming.NameNotFoundException&#58;  $&#123;informixJndiName&#125; not bound
            at org.jnp.server.NamingServer.getBinding&#40;NamingServer.java&#58;495&#41;
            at org.jnp.server.NamingServer.getBinding&#40;NamingServer.java&#58;503&#41;
            at org.jnp.server.NamingServer.getObject&#40;NamingServer.java&#58;509&#41;
            at org.jnp.server.NamingServer.lookup&#40;NamingServer.java&#58;282&#41;
            at org.jnp.interfaces.NamingContext.lookup&#40;NamingContext.java&#58;530&#41;
            at org.jnp.interfaces.NamingContext.lookup&#40;NamingContext.java&#58;509&#41;
            at javax.naming.InitialContext.lookup&#40;InitialContext.java&#58;345&#41;
            at org.springframework.jndi.JndiTemplate.doInContext&#40;JndiTemplate.java&#58;120&#41;
    etc. etc..
    Is this correct behaviour? If so, what is the reason?

    Thanks
    Chris Harris
    Carlisle, UK

  2. #2
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    It works for all inner beans mentioned as properties, but not for constructor arguments. Adding support for constructor arguments shouldn't that much of an issue.

    Juergen, if you're reading this, I'll have a look at this. I'll keep you posted.

  3. #3
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    Errr, too quick. Ignore my previous post. I'll have another look at it ;-)

  4. #4
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    Chris, could you have a look at the isolated test I created. I've attached everything you need to the following JIRA issue.

    I'm using the following context:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC  "-//SPRING//DTD BEAN//EN" "http&#58;//www.springframework.org/dtd/spring-beans.dtd">
    
    <beans>
    
    	<bean id="testBean" class="org.springframework.beans.TestBean">
    		<constructor-arg>
    			<bean class="org.springframework.beans.TestBean">
    				<property name="age"><value>$&#123;age&#125;</value></property>
    			</bean>
    		</constructor-arg>
    	</bean>
    	
    	<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    		<property name="properties">
    			<props>
    				<prop key="age">98</prop>
    			</props>
    		</property>
    	</bean>
    
    </beans>

  5. #5
    Join Date
    Aug 2004
    Location
    Linz, Austria
    Posts
    391

    Default

    Alef, do you already have any insights on this issue? I'm a bit puzzled that this didn't work for constructor arguments before...

    Juergen

  6. #6
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    Err, I forgot to post a link to the JIRA issue. At first sight I thought (from the code) I thougth it was indeed not working for beans passed as constructor arguments, but I've written a test proving that it does.

    http://opensource.atlassian.com/proj...browse/SPR-302

    So unless Chris confirms that it still doesn't work using his config, let's say it works.

  7. #7
    Join Date
    Aug 2004
    Location
    Carlisle, UK
    Posts
    184

    Default

    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 &#123;
    
        public static void main&#40;String&#91;&#93; args&#41; &#123;
            Runner runner = new Runner&#40;&#41;;
            runner.testPropertyPlaceholderConfigurerWithInnerBeansInConstructorArgs&#40;&#41;;
        &#125;
    
        public void testPropertyPlaceholderConfigurerWithInnerBeansInConstructorArgs&#40;&#41; &#123;
            ClassPathXmlApplicationContext ctx =
                    new ClassPathXmlApplicationContext&#40;"test.xml"&#41;;
            ctx.refresh&#40;&#41;;
    
            TestBean tb = &#40;TestBean&#41;ctx.getBean&#40;"testBean"&#41;;
            TestBean spouse = tb.getSpouse&#40;&#41;;
    
            //assertEquals&#40;98, spouse.getAge&#40;&#41;&#41;;
            System.out.println&#40;"spouse.getAge gives " + spouse.getAge&#40;&#41;&#41;;
        &#125;
    &#125;

    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&#58;/usr/j2sdk1.4.2_05/jre/lib/jce.jar&#58;/usr/j2sdk1.4.2_05/jre/lib/charsets.jar&#58;/usr/j2sdk1.4.2_05/jre/lib/plugin.jar&#58;/usr/j2sdk1.4.2_05/jre/lib/rt.jar&#58;/usr/j2sdk1.4.2_05/jre/lib/jsse.jar&#58;/usr/j2sdk1.4.2_05/jre/lib/ext/sunjce_provider.jar&#58;/usr/j2sdk1.4.2_05/jre/lib/ext/dnsns.jar&#58;/usr/j2sdk1.4.2_05/jre/lib/ext/ldapsec.jar&#58;/usr/j2sdk1.4.2_05/jre/lib/ext/localedata.jar&#58;/var/home/dp01/configtest&#58;/user1/spring-framework-1.0.2/dist/spring.jar&#58;/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-attributes-api-SNAPSHOT.jar&#58;/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-attributes-compiler-SNAPSHOT.jar&#58;/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-beanutils.jar&#58;/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-collections.jar&#58;/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-dbcp.jar&#58;/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-digester.jar&#58;/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-discovery.jar&#58;/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-fileupload.jar&#58;/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-lang.jar&#58;/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-logging.jar&#58;/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-pool.jar&#58;/user1/spring-framework-1.0.2/lib/jakarta-commons/commons-validator.jar org.springframework.beans.Runner
    Sep 1, 2004 8&#58;54&#58;50 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
    INFO&#58; Loading XML bean definitions from class path resource &#91;test.xml&#93;
    Sep 1, 2004 8&#58;54&#58;51 AM org.springframework.context.support.AbstractXmlApplicationContext refreshBeanFactory
    INFO&#58; Bean factory for application context &#91;org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=605645&#93;&#58; org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans &#91;testBean,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer&#93;; Root of BeanFactory hierarchy
    Sep 1, 2004 8&#58;54&#58;51 AM org.springframework.context.support.AbstractApplicationContext refresh
    INFO&#58; 2 beans defined in ApplicationContext &#91;org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=605645&#93;
    Sep 1, 2004 8&#58;54&#58;51 AM org.springframework.beans.factory.support.AbstractBeanFactory getBean
    INFO&#58; Creating shared instance of singleton bean 'org.springframework.beans.factory.config.PropertyPlaceholderConfigurer'
    Sep 1, 2004 8&#58;54&#58;51 AM org.springframework.context.support.AbstractApplicationContext initMessageSource
    INFO&#58; No MessageSource found for context &#91;org.springframework.context.support.ClassPathXmlApplicationContext;hashCode=605645&#93;&#58; using empty StaticMessageSource
    Sep 1, 2004 8&#58;54&#58;51 AM org.springframework.context.support.AbstractApplicationContext refreshListeners
    INFO&#58; Refreshing listeners
    Sep 1, 2004 8&#58;54&#58;51 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
    INFO&#58; Pre-instantiating singletons in factory &#91;org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans &#91;testBean,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer&#93;; Root of BeanFactory hierarchy&#93;
    Sep 1, 2004 8&#58;54&#58;51 AM org.springframework.beans.factory.support.AbstractBeanFactory getBean
    INFO&#58; Creating shared instance of singleton bean 'testBean'
    Sep 1, 2004 8&#58;54&#58;51 AM org.springframework.beans.factory.support.AbstractBeanFactory destroySingletons
    INFO&#58; Destroying singletons in factory &#123;org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans &#91;testBean,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer&#93;; Root of BeanFactory hierarchy&#125;
    Exception in thread "main" org.springframework.beans.factory.BeanCreationException&#58; Error creating bean with name 'org.springframework.beans.TestBean' defined in class path resource &#91;test.xml&#93;&#58; Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException&#58; PropertyAccessExceptionsException &#40;1 errors&#41;; nested propertyAccessExceptions are&#58; &#91;org.springframework.beans.TypeMismatchException&#58; Failed to convert property value of type &#91;java.lang.String&#93; to required type &#91;int&#93; for property 'age'; nested exception is java.lang.NumberFormatException&#58; For input string&#58; "$&#123;age&#125;"&#93;
    PropertyAccessExceptionsException &#40;1 errors&#41;
    org.springframework.beans.TypeMismatchException&#58; Failed to convert property value of type &#91;java.lang.String&#93; to required type &#91;int&#93; for property 'age'; nested exception is java.lang.NumberFormatException&#58; For input string&#58; "$&#123;age&#125;"
    java.lang.NumberFormatException&#58; For input string&#58; "$&#123;age&#125;"
    	at java.lang.NumberFormatException.forInputString&#40;NumberFormatException.java&#58;48&#41;
    	at java.lang.Integer.parseInt&#40;Integer.java&#58;468&#41;
    	at java.lang.Integer.valueOf&#40;Integer.java&#58;574&#41;
    	at sun.beans.editors.IntEditor.setAsText&#40;IntEditor.java&#58;21&#41;
    	at org.springframework.beans.BeanWrapperImpl.doTypeConversionIfNecessary&#40;BeanWrapperImpl.java&#58;828&#41;
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValue&#40;BeanWrapperImpl.java&#58;637&#41;
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValue&#40;BeanWrapperImpl.java&#58;568&#41;
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValue&#40;BeanWrapperImpl.java&#58;685&#41;
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValues&#40;BeanWrapperImpl.java&#58;712&#41;
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValues&#40;BeanWrapperImpl.java&#58;701&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues&#40;AbstractAutowireCapableBeanFactory.java&#58;626&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean&#40;AbstractAutowireCapableBeanFactory.java&#58;467&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;232&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveInnerBeanDefinition&#40;AbstractAutowireCapableBeanFactory.java&#58;702&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.resolveValueIfNecessary&#40;AbstractAutowireCapableBeanFactory.java&#58;663&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor&#40;AbstractAutowireCapableBeanFactory.java&#58;307&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;214&#41;
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;177&#41;
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;159&#41;
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons&#40;DefaultListableBeanFactory.java&#58;183&#41;
    	at org.springframework.context.support.AbstractApplicationContext.refresh&#40;AbstractApplicationContext.java&#58;268&#41;
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>&#40;ClassPathXmlApplicationContext.java&#58;58&#41;
    	at org.springframework.beans.Runner.testPropertyPlaceholderConfigurerWithInnerBeansInConstructorArgs&#40;Runner.java&#58;20&#41;
    	at org.springframework.beans.Runner.main&#40;Runner.java&#58;16&#41;
    
    Process finished with exit code 1
    Chris Harris
    Carlisle, UK

  8. #8
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    Forget to ask, you're still using 1.0.2.

    I haven't tried this with 1.0.2, only with the current cvs version.

    I'll have a look later on with 1.0.2. Can't do that now, not at the office.

  9. #9
    Join Date
    Aug 2004
    Location
    Carlisle, UK
    Posts
    184

    Default

    Yes, I'm using 1.0.2

    Waiting for 1.1 Final before I upgrade.
    Chris Harris
    Carlisle, UK

  10. #10
    Join Date
    Aug 2004
    Location
    Amsterdam, Netherlands
    Posts
    450

    Default

    Confirmed

    Well, I've run the test against 1.0.2 and it produced the exact same error as mentioned by Chris.

    And I'm not surprised after having a look at the sources. The 1.0.2 ProperyPlaceHolderConfigurer simply doesn't the overriding of placeholders in child bean definitions.

    So Chris, unfortunately you'll have to wait until 1.1, which is going to be released this or next week anyway.

    cheers,

    Alef

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •