Tuesday, November 23, 2010

How to invoke static methods in Spring?

We can invoke static methods in Spring by using MethodInvokingFactoryBeanThis is a factoryBean which returns a value which is the result of a static or instance method invocation. To use this bean, you define the bean in the application context xml and configure three properties

1) targetClass - this is the class on which the static method need to be invoked
2) targetMethod - this is the name of the static method
3) arguments - you can list the arguments passed to the static method as parameters

The example below is taken from the Spring API reference. 

This example talks about calling a static method then an instance method to get at a Java system property. 



Blog Archive