从 spring 配置调用静态方法
是否可以在Spring配置文件中调用静态方法?
public MyClass {
public static void staticMethod() {
//do something
}
}
<bean id="myBean" class="MyClass">
<!-- invoke here -->
</bean>
是否可以在Spring配置文件中调用静态方法?
public MyClass {
public static void staticMethod() {
//do something
}
}
<bean id="myBean" class="MyClass">
<!-- invoke here -->
</bean>
配置
<bean id="myBean" class="MyClass" factory-method="staticMethod">
<!-- invoke here -->
</bean>
法典
public static MyClass staticMethod() {
//create and Configure a new Instance
}
配置
<bean id="myBean" class="MyClass" init-method="init">
<!-- invoke here -->
</bean>
法典
public static void staticMethod() {
//create and Configure a new Instance
}
public void init() {
staticMethod();
}
试试这个
<bean id="b1" class="org.springframework.beans.factory.config.MethodInvokingBean">
<property name="staticMethod" value="MyClass.staticMethod" />
</bean>