gpt4 book ai didi

hibernate - 在没有 Hibernate 的情况下使用 grails Quartz 插件

转载 作者:行者123 更新时间:2023-12-01 13:07:07 24 4
gpt4 key购买 nike

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

grails install-plugin quartz

然后我创建了一个工作使用

grails create-job My

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

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

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

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 插件 as suggested ,但是一旦删除了 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 使用吗?
(我不关心任何这些数据的持久性。)

最佳答案

我的 Quartz 插件 (0.4.2) 在没有 Hibernate 插件和编辑 Quartz 插件的情况下工作得相当干净。

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

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 session 绑定(bind)到作业线程。像这样创建一个 NOP session Binder :

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) { }
}

关于hibernate - 在没有 Hibernate 的情况下使用 grails Quartz 插件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2287825/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com