如何在spring加载应用程序上下文后执行作业?

问题描述:

我想在加载Spring上下文之后运行一些工作,但我不知道该怎么做。

你知道怎么做吗?

I want to run some jobs just after loading the Spring context but I do not know how to do this.
Do you have any idea how to do that?

谢谢大家的回复。
实际上我在我的问题中错过了一些细节,我想在加载应用程序上下文后运行Quartz Job ..
我尝试了解决方案stakfeman,但是我在运行Quartz Jobs时遇到了一些问题。
最后我找到了解决方案:在Spring中使用Quartz,这里是代码:

thank you all for your reply. In fact I missed a little detail in my question, I wanted to run Quartz Job just after loading the application context.. I tried the solution stakfeman, but I had some problems running the Quartz Jobs. Finally I found that solution: Use Quartz within Spring ,here is the code:

<!--
        ===========================Quartz configuration====================
    -->
    <bean id="jobDetail"
        class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">
        <property name="targetObject" ref="processLauncher" />
        <property name="targetMethod" value="execute" />
    </bean>

    <bean id="simpleTrigger" class="org.springframework.scheduling.quartz.SimpleTriggerBean">
        <!-- see the example of method invoking job above -->
        <property name="jobDetail" ref="jobDetail" />
        <!-- 10 seconds -->
        <property name="startDelay" value="10000" />
        <!-- repeat every 50 seconds -->
        <property name="repeatInterval" value="50000" />
    </bean>

    <bean class="org.springframework.scheduling.quartz.SchedulerFactoryBean">
        <property name="triggers">
            <list>
                <ref bean="simpleTrigger" />
            </list>
        </property>
    </bean>

再次感谢您的帮助,如果问题不是很清楚我会道歉':(

thank you again for the help and I apologize if the question was not very clear ':(