Results 1 to 3 of 3

Thread: How to inject a static class member into a bean property?

  1. #1
    Join Date
    Dec 2009
    Posts
    1

    Default 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. #2
    Join Date
    Nov 2009
    Location
    La Plata, Buenos Aires, Argentina
    Posts
    8

    Default

    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!

  3. #3

    Smile

    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

Posting Permissions

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