Spring inject value into a static field

using org.springframework.beans.factory.config.MethodInvokingFactoryBean to invoke a static setter.

e.g
public Class ClassName{
private static Object fieldName;
public static void setFieldName(final Object fieldName)
{
ClassName.fieldName = fieldName;
}
}

Spring Injection:

<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="staticMethod" value="package.ClassName.setFieldName" />
<property name="arguments">
<list>
<ref bean="refObject" />
</list>
</property>
</bean>

Ref:

Advertisements

About Lekshmana Perumal M

Proud be an Indian, passion to teaching & learn, love mathematics, enjoy with family & friends, job to code. Care about child education, Indian culture
This entry was posted in JAVA, spring and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s