在JobDetailBean中注入对作业类的bean引用

时间:2016-07-20 12:47:38

标签: java spring spring-batch quartz-scheduler

我使用弹簧批和石英调度器每5秒触发一次作业。

<bean name="JobA" class="org.springframework.scheduling.quartz.JobDetailBean">
        <property name="jobClass" value="com.batch.test.FirstJob" />
</bean>

这里不是传递类本身就可以传递bean的引用吗?

<bean id="firstJob" class="com.batch.test.FirstJob">
        <property name="sessionFactory" ref="sessionFactory"> </property>
    </bean>
<bean name="JobA" class="org.springframework.scheduling.quartz.JobDetailBean">
            <property name="jobClass" ref="firstJob" />
    </bean>

这可能吗?

2 个答案:

答案 0 :(得分:0)

是。它完全取决于你的用例。

考虑下面的课程:

  public ClassA{

      private Class clazz;
      private FirstJob firstJob;

      public Class getClazz() {
          return clazz;
      }

      public void setClazz(Class clazz) {
          this.clazz = clazz;
      }

      public FirstJob getFirstJob() {
          return firstJob;
      }

      public void setFirstJob(FirstJob firstJob) {
         this.firstJob = firstJob;
      }
}

依赖注入:

 <bean id="firstJob" class="com.batch.test.FirstJob">
    <property name="sessionFactory" ref="sessionFactory"> </property>
</bean>

<bean name="JobA" class="org.springframework.scheduling.quartz.JobDetailBean">
        <property name="clazz" value="com.batch.test.FirstJob" />
        <property name="firstJob" ref="firstJob" />
</bean>

答案 1 :(得分:0)

最后才知道必须要做什么。

WebDriver driver = new FirefoxDriver(profile);

希望有一天对某人有用:)