Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Spring Bean Value

  1. #1
    Member
    Join Date
    Feb 2011
    Posts
    33
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Spring Bean Value

    Okay, so we have an application that uses Spring 2. I have a bean that accesses a method which returns a username (process ID) and password to be used in a database connection. The problem I am having is retrieving those values. Spring 2 seems to want to return the literal values for the property values (ie. #{pid.username} instead of the value of username). Here is what I have...

            <bean id="pidReader" class="com.blah.biz.securepid.DefaultPIDReader" />
     
    	<bean id="pid" factory-bean="pidReader" factory-method="readPIDCredentials">
    		<constructor-arg value="arg" />
    	</bean>
     
    	<bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource">
    		<property name="username">
    			<value>#{pid.username}</value>
    		</property>
    		<property name="password">
    			<value>#{pid.password}</value>
    		</property>
    		<property name="driverClassName">
    			<value>driver</value>
    		</property>
    		<property name="url">
    			<value>url</value>
    		</property>
    	</bean>

    The DefaultPIDReader class is located in a library that is referenced by the main app. This works fine for the apps that are running Spring 3. Is there any way in Spring 2 to return the value of pid.username. Someone mentioned using the util namespace, but I cannot find anything that works. And upgrading to Spring 3 (on this app anyway) is not an option.


    All intelligent thoughts have already been thought;
    what is necessary is only to try to think them again.




  2. #2
    Member
    Join Date
    Feb 2011
    Posts
    33
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: Spring Bean Value

    Found the solution. If using Spring 3, <value>#{username}</value> works. If using Spring 2, <util:property-path path="bean.username"/> is equivalent.


    All intelligent thoughts have already been thought;
    what is necessary is only to try to think them again.



Similar Threads

  1. Which API resolves all the Bean references?
    By tcstcs in forum Web Frameworks
    Replies: 0
    Last Post: January 5th, 2012, 12:48 AM
  2. Could not instantiate bean class
    By Sheval in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 21st, 2011, 03:40 PM
  3. Instantiation of bean failed
    By peejayuk in forum Member Introductions
    Replies: 1
    Last Post: August 15th, 2011, 02:35 PM
  4. [SOLVED] What do I need to do to use a bean in Netbeans 7 apart from defining it?
    By Lord Voldemort in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: July 31st, 2011, 12:29 AM
  5. converting HashMap to a Bean
    By achsu in forum Collections and Generics
    Replies: 0
    Last Post: February 2nd, 2011, 09:13 PM