title: Injecting a Transactional Grails Service into a Quartz Plugin Job gives BeanCreationExecption
body: <p>Grails version: 2.3.5
  Quartz plugin version: 1.0.2</p>
  
  <p>I am creating a internal Grails Plugin. This plugin has a dependency on the Grails Quartz Plugin.</p>
  
  <p>I have a Grails Service: OrchestratorJobExecutorService</p>
  
  <pre><code>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
      }
  }
  </code></pre>
  
  <p>I have a Quartz Job: OrchestratorJob</p>
  
  <pre><code>public class OrchestratorJob {
      def orchestratorJobExecutorService
      static triggers = {cron cronExpression: "0 0 15 * * ? *"}
      def group = "orchestrator"
      public execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
          orchestratorJobExecutorService.execute()
      }
  }
  </code></pre>
  
  <p>When this job executes I get a org.springframework.beans.factory.BeanCreationException</p>
  
  <pre><code>....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
  </code></pre>
  
  <p>I don't have much special in myPluginGrailsPlugin.groovy file. The few lines I've changed besides the basic plugin version/description/documentation lines are:</p>
  
  <pre><code>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*/]
  </code></pre>
  
  <p>I don't have anything else defined in any of the doWith* closures or the on* closures</p>
  
  <p>If I add <code>static transactional = false</code> to my OrchestratorJobExecutorService, the error goes away. I have several jobs and services and I've had to go through my entire plugin and set every service to be non-transactional. I don't really feel comfortable with that, moving away from a transactional service scares me. In the main application where this plugin is going to be used, there is going to be a lot of database interaction in some plugin artefacts I've created.</p>
  
  <p>Anyone know how I can keep my services transactional and still have them be injected?</p>
  
  <p>=====Edit 10/20/2014=====</p>
  
  <p>Added hibernate 3 dependency:</p>
  
  <pre><code>runtime ":hibernate:3.6.10.17"
  </code></pre>
  
  <p>New error:</p>
  
  <pre><code>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
  </code></pre>
  
  <p>Running <code>clean-all</code> and <code>refresh-dependencies</code> several times didn't seem to resolve the error (that's my standard procedure when I get errors I can't make sense of).</p>
  
  <p><strong>BuildConfig.groovy</strong></p>
  
  <pre><code>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://&lt;mySnapshotRepoUrl&gt;"
  grails.project.repos.releaseArtifactory.url = "http://&lt;myReleaseRepoUrl&gt;"
  grails.project.repos.snapshotArtifactory.username = "&lt;topSecretUsername&gt;"
  grails.project.repos.snapshotArtifactory.password = '&lt;topSecretPassword&gt;'
  
  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://&lt;mySnapshotRepoUrl&gt;"){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.&lt;myCompany&gt;.plugins:myOtherPlugin:0.1-SNAPSHOT"
          compile ":quartz:1.0.2"
          runtime ":hibernate:3.6.10.17"
      }
  }
  </code></pre>