繁体   English   中英

将事务性Grails服务注入到Quartz插件作业中可以得到BeanCreationExecption

[英]Injecting a Transactional Grails Service into a Quartz Plugin Job gives BeanCreationExecption

Grails版本:2.3.5 Quartz插件版本:1.0.2

我正在创建一个内部Grails插件。 该插件依赖于Grails Quartz插件。

我有一个Grails服务:OrchestratorJobExecutorService

public class OrchestratorJobExecutorService {
    def grailsApplication
    def jobManagerService

    public void execute() {
        //do a bunch of stuff using here 
        //using grailsApplication to find a bunch of artifacts I've created in this plugin
        //using jobManagerService to check if trigger exists, then re/schedule job as needed
    }
}

我有一个石英作业:OrchestratorJob

public class OrchestratorJob {
    def orchestratorJobExecutorService
    static triggers = {cron cronExpression: "0 0 15 * * ? *"}
    def group = "orchestrator"
    public execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        orchestratorJobExecutorService.execute()
    }
}

执行此作业时,我收到org.springframework.beans.factory.BeanCreationException

....core.ErrorLogger An error occured instantiating job to be executed. job= 'myPlugin.com.bgc.OrchestratorJob'
org.quartz.SchedulerException: Job instantiation failed [See nested exception: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.bgc.TamiOrchestratorJob': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myPluginOrchestratorJobExecutorService': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager' is defined]
    at org.quartz.core.JobRunShell.initialize(JobRunShell.java:127)
    at org.quartz.core.QuartzSchedulerThread.run(QuartzSchedulerThread.java:375)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.bgc.OrchestratorJob': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myPluginOrchestratorJobExecutorService': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager' is defined
    at grails.plugins.quartz.GrailsJobFactory.createJobInstance(GrailsJobFactory.java:48)
    ... 2 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myPluginOrchestratorJobExecutorService': Cannot resolve reference to bean 'transactionManager' while setting bean property 'transactionManager'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager' is defined
    ... 3 more
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'transactionManager' is defined
    ... 3 more

我的myPluginGrailsPlugin.groovy文件没有什么特别之处。 除了基本的插件版本/说明/文档行之外,我更改的几行是:

def loadAfter = ['controllers','services','spring-security-core','quartz','myOtherPlugin']
def pluginExcludes = [/*a bunch of folders with files I use to test and run my plugin*/]

在任何doWith *闭包或on *闭包中,我没有定义任何其他内容

如果我向OrchestratorJobExecutorService添加static transactional = false ,则错误会消失。 我有几个工作和服务,我必须遍历整个插件并将每个服务设置为非事务性的。 我对此真的不满意,离开交易服务使我感到恐惧。 在将要使用此插件的主应用程序中,在我创建的某些插件工件中,将会有很多数据库交互。

有谁知道我可以如何保持服务的事务性并仍然注入它们?

=====编辑10/20/2014 =====

添加了休眠3依赖关系:

runtime ":hibernate:3.6.10.17"

新错误:

context.GrailsContextLoader Error initializing the application: org.springframework.beans.factory.annotation.InjectionMetadata.needsRefresh(Lorg/springframework/beans/factory/annotation/InjectionMetadata;Ljava/lang/Class;)Z
java.lang.NoSuchMethodError: org.springframework.beans.factory.annotation.InjectionMetadata.needsRefresh(Lorg/springframework/beans/factory/annotation/InjectionMetadata;Ljava/lang/Class;)Z
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)
    at java.util.concurrent.FutureTask.run(FutureTask.java:138)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
    at java.lang.Thread.run(Thread.java:662)
Error |
Forked Grails VM exited with error

多次运行clean-allrefresh-dependencies似乎无法解决错误(这是我遇到错误时无法理解的标准过程)。

BuildConfig.groovy

grails.project.class.dir = "target/classes"
grails.project.test.class.dir = "target/test-classes"
grails.project.test.reports.dir = "target/test-reports"

grails.release.scm.enabled = false

grails.project.repos.snapshotArtifactory.url = "https://<mySnapshotRepoUrl>"
grails.project.repos.releaseArtifactory.url = "http://<myReleaseRepoUrl>"
grails.project.repos.snapshotArtifactory.username = "<topSecretUsername>"
grails.project.repos.snapshotArtifactory.password = '<topSecretPassword>'

grails.project.fork.test = false
grails.project.fork = [
    run: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
    war: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256, forkReserve:false],
    console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
]

grails.project.dependency.resolver = "maven"
grails.project.dependency.resolution = {
    inherits("global") {}

    log "warn"

    repositories {
        grailsCentral()
        mavenCentral()
        mavenRepo ("https://<mySnapshotRepoUrl>"){updatePolicy "always"}
    }

    dependencies {
        compile("org.hamcrest:hamcrest-all:1.3")
    }

    plugins {
        build ":release:3.0.1"
        build (":tomcat:7.0.50"){export=false}
        compile "com.<myCompany>.plugins:myOtherPlugin:0.1-SNAPSHOT"
        compile ":quartz:1.0.2"
        runtime ":hibernate:3.6.10.17"
    }
}

您是否安装了Hibernate插件或另一个GORM插件? 我认为您不会走得太远,但这就是transactionManager bean的来源。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM