Skip to content

Instantly share code, notes, and snippets.

@relax-more
Created July 24, 2015 07:56
Show Gist options
  • Save relax-more/6a7842648c2d00ed4598 to your computer and use it in GitHub Desktop.
Save relax-more/6a7842648c2d00ed4598 to your computer and use it in GitHub Desktop.
[java] DI data to static field with spring
<?xml version="1.0" encoding="UTF-8" ?>
<beans
http://www.springframework.org/schema/beans/spring-beans.xsd"
>
<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
<property name="staticMethod" value="jp.co.myProject.MyClass.setStaticField" />
<property name="arguments">
<value>staticFieldValue</value>
</property>
</bean>
</beans>
public Class MyClass{
private static String staticFieldValue;
public static void setStaticField(String staticFieldValue){
this.staticFieldValue = staticFieldValue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment