Announcement Announcement Module
Collapse
No announcement yet.
Setting bean property question Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Setting bean property question

    Hi,
    I'm really very new to spring. Infact I'm writing my first program in spring.
    I have to set a bean property in bean configuration xml file with a value that is defined in as a public static final member of an interface. In java program I write the code as
    Code:
    setTransportType(com.ibm.mq.jms.JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
    How do I write the same in bean xml file. BTW com.ibm.mq.jms.JMSC.MQJMS_TP_CLIENT_MQ_TCPIP is of type int.
    Thanks

  • #2
    I guess this is not a place to ask newbie questions. Can someone please tell me where I can direct newbie questions?
    Thanks

    Comment


    • #3
      Perhaps someone else can confirm whether this works, but have you looked at "org.springframework.beans.factory.config.FieldRet rievingFactoryBean"...

      The documentation indicates "FactoryBean which retrieves a static or non-static field value. Typically used for retrieving public static final constants."

      Not sure if you can use it with primitive types?

      Tim

      Comment


      • #4
        You can use either
        Code:
           <bean id="const" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
             <property name="targetClass">
              <value>com.ibm.mq.jms.JMSC</value>
             </property>
             <property name="targetField">
              <value>MQJMS_TP_CLIENT_MQ_TCPIP</value>
             </property>
           </bean>
        or
        Code:
           <bean id="const" class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean">
            <property name="staticField">
              <value>com.ibm.mq.jms.JMSC.MQJMS_TP_CLIENT_MQ_TCPIP</value>
            </property>
           </bean>
        HTH

        Comment


        • #5
          Thanks a lot Tim and Omar. Worked fine for me indeed with org.springframework.beans.factory.config.FieldRetr ievingFactoryBean.
          I confirm that it does work with primitives too not just objects. Thanks again.

          Comment

          Working...
          X