2014-05-02 37 views
1

即時通訊創建一個由groovy bean構建器支持的spring批處理(spring-boot)。但是我不是能找到以下XML構造正確的語法:Spring批處理作業庫的Groovy bean語法

<batch:job-repository/> 

更新: beans.groovy

beans { 

    xmlns([ctx: 'http://www.springframework.org/schema/context', batch: 'http://www.springframework.org/schema/batch']) 
    ctx.'component-scan'('base-package': 'mypackage') 
    ctx.'annotation-config'() 


    itemReader(MyItemReader) {} 

    itemProcessor(MyItemProcessor) {} 

    itemWriter(FlatFileItemWriter) { ... } 

    batch.job(id: 'job1') { 
     batch.step(id: 'step1') { 
      batch.tasklet { 
       batch.chunk(
        reader: 'itemReader', 
        writer: 'itemWriter', 
        processor: 'itemProcessor', 
        'commit-interval': 1 
       ) 
      } 
     } 
    } 

    //Option 1: will this work? 
    //batch.'job-repository'() 

    //Option 2: all job related beans defined individually, because cannot get <batch:job-repository/> in groovy bean syntax 
    jobRepository(MapJobRepositoryFactoryBean) { 
     transactionManager = ref('transactionManager') 
    } 

    jobRegistry(MapJobRegistry) { } 

    jobLauncher(SimpleJobLauncher) { 
     jobRepository = ref('jobRepository') 
     taskExecutor = { SyncTaskExecutor executor -> } 
    } 

    jobExplorer(JobExplorerFactoryBean) { 
     dataSource = ref('dataSource') 
    } 

    jobOperator(SimpleJobOperator) { 
     jobLauncher = ref('jobLauncher') 
     jobRepository = ref('jobRepository') 
     jobRegistry = ref('jobRegistry') 
     jobExplorer = ref("jobExplorer") 
    } 

} 

我想用選項1的技術,如果我這樣做,我get'beanName不能爲空'錯誤。而不是我使用選項2中的bean,它們似乎正在工作。

我假設使用選項1,將使用其他定義的bean自動配置jobRepository等。

+0

你可以發表你目前有什麼? –

+0

@MichaelMinella我已更新完整配置的帖子。選項2工作正常,但我正在尋找選項1技術語法。感謝幫助! – vasya10

+2

是的,這個命名空間選項沒有特別的Groovy支持,所以選項2是唯一的選擇。我們正在研究Groovy DSL,但目前尚不可用。 –

回答

0

我爲命名空間選項添加了Jira ticket。然而,當你使用Groovy DSL相結合註釋,你也可以解決這個問題,下面的春季啓動批量的例子:

如果你有一個應用程序類,你可以用@EnableBatchProcessing註釋它來獲得所要求的行爲:

import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing 
import org.springframework.boot.autoconfigure.EnableAutoConfiguration 
import org.springframework.boot.builder.SpringApplicationBuilder 
import org.springframework.context.annotation.ComponentScan 

@ComponentScan 
@EnableAutoConfiguration 
@EnableBatchProcessing 
public class Application 
{ 
    public static void main(String[] args) 
    { 
     new SpringApplicationBuilder(Application.class, "appcontext.groovy").run(args) 
    } 
} 

但是,您沒有在一個地方完成所有配置。

相關問題