Results 1 to 2 of 2

Thread: Using Class Constants in Spring.xml

  1. #1
    Join Date
    Aug 2004
    Posts
    4

    Default Using Class Constants in Spring.xml

    How do I pass a Class constant to a bean property in a spring.xml file? Here's a sample spring.xml entry illustrating what I'm trying to configure:
    Code:
    <bean id="myBean" class="MyClass">
        <property name="configValue">
            <value>MyOtherClass.CONFIG_VALUE</value>
        </property>
    </bean>
    I found the following Spring classes but don't know how can I use them in the spring.xml file:

    Constants http://www.springframework.org/docs/...Constants.html
    FieldRetrievingFactoryBean file:///home/jojo/java-api/spring-fr...ctoryBean.html

    For me the Constants class fits my need although I'm not sure how to use it in spring.xml. Any tips on how to use it?

  2. #2
    Join Date
    Aug 2004
    Posts
    2,715

    Default

    The factory can be used like this:

    Code:
    <bean id="myBean" class="MyClass">
        <property name="configValue">
          <bean class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" >
              <property name="targetClass">
                 <value>MyOtherClass</code>
              </property>
    
              <property name="targetField">
                 <value>CONFIG_VALUE</code>
              </property>
         </bean>
        </property>
    </bean>
    Note that the classname has to be fully qualified.

    Hope that helps,
    Andreas

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. Replies: 3
    Last Post: Sep 4th, 2005, 11:11 PM
  5. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM

Posting Permissions

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