如何将null作为方法参数与Spring连接?

时间:2017-10-10 09:00:46

标签: java spring

我正在尝试使用null参数调用自定义方法。我试图使用arguments属性与元素。但我收到了以下错误。有没有办法做到这一点?

<bean id="customJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    <property name="targetObject" ref="customExecutor" />
    <property name="targetMethod" value="run" />
    <property name="arguments">
        <null/>
    </property>
</bean>

我收到了以下错误;

Error creating bean with name 'customJob'
java.lang.NoSuchMethodException: total.scheduler.CustomExecutor.run()

我的CustomExecutor类方法;

public void run(Object object){
....
}

1 个答案:

答案 0 :(得分:2)

请尝试以下代码:

<bean id="customJob" class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
    <property name="targetObject" ref="customExecutor" />
    <property name="targetMethod" value="run" />
    <property name="arguments">

    <property name="arguments">
        <list>
            <null/>
        </list>
    </property>
</bean>