zhanhongbo1112 2009-11-29 20:08
浏览 272
已采纳

在Spring注解驱动配置下使用Quartz调度有问题,大家帮忙看看

最近一直在使用JSF+Hibernate+Spring的配置进行项目二期的重构与开发,并采用了注解的方式,确实减少了很大的工作量。

但目前碰到一个问题,就是需要在其中使用调度程序,每天执行一些调度处理。

之前一期项目中使用了XML配置方式,调度能正常运行,而现在采用注解后就不行了。
代码如下:
[code="java"]
/**

  • 报表调度器
  • @author angeltears 2009-11-22
  • */
    public class ReportScheduler {
    protected Logger logger = LoggerFactory.getLogger(ReportScheduler.class);

    private static final int SIZE_PER_TIME = 5000;

    private ReportCatalogBS reportCatalogBS;

    private RptModifyIntBS rptModifyIntBS;

    public void doFromModify2MakeJob() {
    ......
    }

     public void doSummaryJob() {
         ......
     }
    

    }
    [/code]
    此类用于执行调度,方法doFromModify2MakeJob和doSummaryJob都是调度执行的方法。它们在不同的时间点分别执行。
    XML配置文件如下:
    [code="java"]
    <?xml version="1.0" encoding="UTF-8"?>
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
    http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"
    default-lazy-init="true">

    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">




    <!-- 标准配置 -->
    classpath*:/application.properties

    <!-- 本地开发环境配置 -->
    <!-- value>classpath*:/application.local.properties
    <!-- 服务器生产环境配置 -->
    <!-- file:/var/myapp/application.server.properties -->



    p:driverClassName="${jdbc.driverClassName}" p:url="${jdbc.url}"
    p:username="${jdbc.username}" p:password="${jdbc.password}"
    p:initialSize="5" p:maxActive="100" p:maxIdle="30" p:maxWait="1000"
    p:poolPreparedStatements="true" p:defaultAutoCommit="false" />





    class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
    p:dataSource-ref="dataSource">





    ${hibernate.dialect}
    ${hibernate.show_sql}
    ${hibernate.format_sql}
    ${hibernate.generate_statistics}


    ${hibernate.cache.use_query_cache}


    ${hibernate.cache.use_second_level_cache}

    ${hibernate.use_sql_comments}

    ${hibernate.jdbc.fetch_size}

    ${hibernate.jdbc.batch_size}


    ${hibernate.query.factory_class}


    ${hibernate.cache.provider_class}

    ${hibernate.ehcache_config_file}



    value="com.fenet.gddb.cds.model.*,com.fenet.gddb.cds.model.*.*,com.fenet.gddb.cds.model.*.*.*" />

    class="org.springframework.orm.hibernate3.HibernateTransactionManager">







    class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">





    <!-- 每天18点10分到20点执行,每隔1分钟执行一次 -->

    <!-- 每月的最后一天18点10分开始到20点之间,每隔1分钟运行一次的执行 -->
    <!--property name="cronExpression" value="0 10/1 18,20 L * ?" /-->

    class="org.springframework.scheduling.quartz.MethodInvokingJobDetailFactoryBean">





    <!-- 每天0点至6点执行,每隔30分钟运行一次 -->











    [/code]
    Web.xml中的ContextLoaderListener和contextConfigLocation都配置了,但在指定的时间内,却一点反应也没有,请各路英雄解救下!谢谢了
    [b]问题补充:[/b]
    我明天试试,谢谢!

另外,spring封装quartz类SchedulerFactoryBean不能使用惰加载,和 lazy-init="true" > 是冲突的吧?不能使用惰加载不是应该设置为lazy-init="false"吗

  • 写回答

3条回答 默认 最新

  • wanghaolovezlq 2009-11-29 23:26
    关注

    就是因为你配置了 default-lazy-init="true" 导致定时器加载失败

    spring的ioc容器默认在启动时加载整个对象实例图,只要配置根元素beans的 default-lazy-init ="true" 就能让spring不加载整个对象实例图。

    特别要注意的是

    spring封装quartz类

    不能使用惰加载,否则定义的触发器都将失效。

    正确的配置如下:

    <bean class ="org.springframework.scheduling.quartz.SchedulerFactoryBean"

    lazy-init="true" >

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!