Announcement Announcement Module
Collapse
No announcement yet.
How to inject a static class member into a bean property? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to inject a static class member into a bean property?

    I have a bean that has a property -- call it fooList -- that is of type List<Foo> . I have another class that has a static member MyOtherClass.FOO_LIST that is of type List<Foo> . How do I inject that static member as the value of the fooList property? In other words ...

    <bean id="abc" class="myBean">

    <property name="fooList">
    // what goes here if I want to set fooList to the static MyOtherClass.FOO_LIST member?
    </property>

    </bean>

    Can this be done? If so, how?

    Thanks in advance.

    --Jim

  • #2
    Maybe you can use the util:constant element, it's for accessing to static field defined in somewhere.
    Try this
    Code:
    <property name=“fooList”>
        <util:constant static-field=“MyOtherClass.FOO_LIST” />
      </property>
    Don't forget to import the util namespace into your xml configuration file. See in the reference how to do it: http://static.springsource.org/sprin...sd-config.html.

    In this link you've got some information about util:constant too.

    Good luck!

    Comment


    • #3
      Hi ,

      It is not possible to "SET A STATIC MEMBER FIELD" in Spring.We had faced this issue eralier also wher we had a static field and couldn't set throught <property > tag.

      Util:contant or FieldRetrievingFactoryBean "RETRIEVES A STATIC VALUE FROM THE VALUE MENTIONED IN static-field" and will sets it to fooList,provided foolist needs to be non static member in MYOtherClass.

      <property name=“fooList”>
      <util:constant static-field=“MyOtherClass.FOO_LIST” />
      </property>


      Hope it helps

      kartik

      Comment

      Working...
      X