使用没有Hibernate的grails Quartz插件(Using the grails Quartz plugin without Hibernate)

编程入门 行业动态 更新时间:2024-10-26 14:30:12
使用没有Hibernate的grails Quartz插件(Using the grails Quartz plugin without Hibernate)

我正在开发一个后端Grails应用程序,它定期从RESTful服务中提取信息。 为此,我安装了Grails Quartz插件。

grails install-plugin quartz

然后我创建了一份工作

grails create-job My

它生成一个我用cron触发器配置的MyJob文件

static triggers = { cron name: 'myTrigger', cronExpression: '0 0 * * * ?' // hourly }

在开发环境中本地运行应用程序可以正常工作,但是一旦我尝试构建测试或生产战争,我就会在运行触发器时遇到以下异常。

2010-02-18, 00:04:32 ERROR org.codehaus.groovy.grails.web.context.GrailsContextLoader - Error occurred shutting down plug-in manager: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'quartzScheduler': Cannot resolve reference to bean 'sessionBinderListener' while setting bean property 'jobListeners' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionBinderListener': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is java.sql.SQLException : Access is denied: Session is closed

由于我不需要数据库,我尝试按照建议删除Hibernate插件,但是一旦Hibernate插件被删除,我就会遇到编译问题:

Running script C:\Downloads\grails-1.2.1\scripts\RunApp.groovy Environment set to development [groovyc] Compiling 18 source files to C:\Projects\myapp\target\classes [groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, Compile error during compilation with javac. [groovyc] ...\myapp\plugins\quartz-0.4.1\src\java\org\codehaus\groovy\grails\plugins\quartz\listeners\SessionBinderJobListener.java:19: package org.hibernate does not exist [groovyc] import org.hibernate.FlushMode; ...

有没有办法在没有Hibernate插件的情况下使用Quartz插件? 如果没有,最好的想法是配置一个内存数据库供Quartz使用吗? (我不关心任何这些数据的持久性。)

I am working on a backend Grails application that pulls information periodically from a RESTful service. To do this I installed the Grails Quartz plugin.

grails install-plugin quartz

I then created a job using

grails create-job My

which geneates a MyJob file which I configured with a cron trigger

static triggers = { cron name: 'myTrigger', cronExpression: '0 0 * * * ?' // hourly }

Running the application locally in the dev environment works correctly, however once I try to build a testing or production war I get the following exception when the trigger is run.

2010-02-18, 00:04:32 ERROR org.codehaus.groovy.grails.web.context.GrailsContextLoader - Error occurred shutting down plug-in manager: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'quartzScheduler': Cannot resolve reference to bean 'sessionBinderListener' while setting bean property 'jobListeners' with key [0]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionBinderListener': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Cannot resolve reference to bean 'hibernateProperties' while setting bean property 'hibernateProperties'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'hibernateProperties': Cannot resolve reference to bean 'dialectDetector' while setting bean property 'properties' with key [hibernate.dialect]; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dialectDetector': Invocation of init method failed; nested exception is org.springframework.jdbc.support.MetaDataAccessException: Error while extracting DatabaseMetaData; nested exception is java.sql.SQLException : Access is denied: Session is closed

As I don't require a database, I tried removing the Hibernate plugin as suggested, but I get compilation problems once the Hibernate plugin has been removed:

Running script C:\Downloads\grails-1.2.1\scripts\RunApp.groovy Environment set to development [groovyc] Compiling 18 source files to C:\Projects\myapp\target\classes [groovyc] org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, Compile error during compilation with javac. [groovyc] ...\myapp\plugins\quartz-0.4.1\src\java\org\codehaus\groovy\grails\plugins\quartz\listeners\SessionBinderJobListener.java:19: package org.hibernate does not exist [groovyc] import org.hibernate.FlushMode; ...

Is there any way to use the Quartz plugin without the Hibernate plugin? If not, would the best idea be to configure an in-memory database for Quartz to use? (I'm not concerned with the persistence of any of this data.)

最满意答案

我得到了Quartz插件(0.4.2),没有Hibernate插件,没有编辑Quartz插件,工作得相当干净。

在BuildConfig.groovy中添加运行时依赖Hibernate只是为了拉入jar:

dependencies { ... // the Quartz plugin depends on some Hibernate classes being available runtime('org.hibernate:hibernate-core:3.6.7.Final') { exclude group:'commons-logging', name:'commons-logging' exclude group:'commons-collections', name:'commons-collections' exclude group:'org.slf4j', name:'slf4j-api' exclude group:'xml-apis', name:'xml-apis' exclude group:'dom4j', name:'dom4j' exclude group:'antlr', name:'antlr' } }

Quartz仍然安装一个SessionBinderJobListener来将Hibernate会话绑定到作业线程。 像这样创建一个NOP会话绑定器:

import org.quartz.listeners.JobListenerSupport class NopSessionBinderJobListener extends JobListenerSupport { String getName() { return "sessionBinderListener" } }

并在resources.groovy中创建一个Spring bean:

beans = { ... // dummy session binder to work around issue with Quartz requiring Hibernate sessionBinderListener(NopSessionBinderJobListener) { } }

I've managed to get this working by leaving the Hibernate plugin installed and configuring the in-memory database. In DataSource.groovy

... environments { development { dataSource { dbCreate = "create-drop" // one of 'create', 'create-drop','update' url = "jdbc:hsqldb:mem:myDevDb" } } test { dataSource { dbCreate = "create-drop" url = "jdbc:hsqldb:mem:myTestDb" } } production { dataSource { dbCreate = "create-drop" url = "jdbc:hsqldb:mem:myProdDb;shutdown=true" } } } ...

The change was to set "create-drop" on the test & production databases and set the production database to 'mem' instead of 'file'.

更多推荐

本文发布于:2023-08-05 19:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1439368.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:插件   grails   Hibernate   plugin   Quartz

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!