-1

How to inject static variables from spring bean?

public class MyClass{
    static String str;
    // how to set value to this variable through Spring
}

<b>Spring bean</b>
<bean id='myclass' class = 'com.so.MyClass'>
    <property name="str" value="xmlpath" />
</bean>.
stealthjong
  • 10,858
  • 13
  • 45
  • 84
Learner
  • 521
  • 1
  • 6
  • 16

2 Answers2

0

You can use a none static setter for your static variable

public void setStr(String str) {
    your.package.MyClass.str = str;
}

and in your context :

<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="yourMethod" value="your.packaged.MyClass.setStr"/>
    <property name="arguments">
        <list>
            <ref bean="str"/>
        </list>
   </property>
</bean>
Arno_Geismar
  • 2,296
  • 1
  • 15
  • 29
0

In property tag property name would be "staticMethod" according to me

Ridhi
  • 105
  • 8