在JobRepository中检测到现有事务-带有Grails插件的Spring批处理

在JobRepository中检测到现有事务-带有Grails插件的Spring批处理,grails,spring-batch,Grails,Spring Batch,每次启动批处理作业时,它都会抛出一个IllegalStateException,并表示它在JobRepository中检测到一个事务。我做了一些研究,删除了代码中所有的@Transactional注释 我使用您可以找到的GrailsSpring批处理插件,我使用Grails2.3.11和Java8。我的代码如下所示: SimpleJobBatchConfig.groovy BatchTestController.groovy BatchTestService.groovy simplejobsk

每次启动批处理作业时,它都会抛出一个IllegalStateException,并表示它在JobRepository中检测到一个事务。我做了一些研究,删除了代码中所有的
@Transactional
注释

我使用您可以找到的GrailsSpring批处理插件,我使用Grails2.3.11和Java8。我的代码如下所示:

SimpleJobBatchConfig.groovy BatchTestController.groovy BatchTestService.groovy simplejobsklet.groovy
Grails服务在默认情况下是事务性的。您可以使用
@Transactional
自定义整个类或每个方法的设置,但如果没有注释,则与使用类范围Spring
@Transactional
注释相同

要使您的服务非事务性,请添加
static transactional=false
,例如

class BatchTestService {

    static transactional = false

    def springBatchService

    ...
    }
}

非常感谢你!我对Grails还是个新手,很高兴知道默认情况下每个服务都是
@transactional
class BatchelorController {

    def batchTestService

    def index() {

    }

    def launchSimpleJob() {
        batchTestService.launchSimpleJob()
    } 
}
class BatchTestService {

    def springBatchService

    def launchSimpleJob() {
        springBatchService.launch("simpleJob")
    }

}
class SimpleJobTasklet implements Tasklet {

    @Override
    RepeatStatus execute(StepContribution stepContribution, ChunkContext chunkContext) throws Exception {
        println("Hello World!")
        return RepeatStatus.FINISHED
    }

}
class BatchTestService {

    static transactional = false

    def springBatchService

    ...
    }
}