将事务Grails服务注入Quartz插件作业会产生BeanCreationExecption

时间:2014-10-17 21:46:59

标签: grails grails-plugin

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

我有一个Quartz Job: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 *闭包中定义任何其他内容

如果我将static transactional = false添加到我的OrchestratorJobExecutorService,则错误消失。我有几个工作和服务,我必须通过我的整个插件并将每个服务设置为非事务性的。我对此感到不舒服,远离交易服务让我害怕。在将要使用此插件的主应用程序中,我创建的一些插件文件中将会有很多数据库交互。

任何人都知道如何保持我的服务交易并仍然注入它们?

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

添加了hibernate 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"
    }
}

1 个答案:

答案 0 :(得分:0)

您是否安装了Hibernate插件或其他GORM插件?如果没有,我认为你不会有这么远,但transactionManager豆来自哪里。