亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在作業中輸入參數

如何在作業中輸入參數

汪汪一只貓 2022-06-15 10:09:01
我正在嘗試通過控制臺輸入特定參數以運行作業,如下所示:@Value("#{jobParameters['inputFileName']}")public void setFileName(final String name) {    inputFileName = name;}輸入參數是 inputFileName,定義為“ficheroEntrada.csv”,如下所示: https ://imgur.com/m2jVoEB但我收到此錯誤:org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'batchConfiguration': Unsatisfied dependency expressed through method 'setFileName' parameter 0; nested exception is org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1008E: Property or field 'jobParameters' cannot be found on object of type 'org.springframework.beans.factory.config.BeanExpressionContext' - maybe not public or not valid?                at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:666) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]                at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:90) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]                at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:372) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]我是春季批次世界的新手,我真的不知道我做錯了什么......提前感謝您的幫助。
查看完整描述

2 回答

?
泛舟湖上清波郎朗

TA貢獻1818條經驗 獲得超3個贊

要綁定作業參數,您需要將后期綁定功能與StepScope.


您需要做的是將您的 setter 定義為步進范圍的 bean。在您的情況下,一種典型的方法是將項目閱讀器聲明為 bean 并按如下方式傳遞作業參數:


@Bean

@StepScope

public FlatFileItemReader flatFileItemReader(@Value("#{jobParameters['inputFileName']}") String name) {

   return new FlatFileItemReaderBuilder<Foo>()

               .name("flatFileItemReader")

               .resource(new FileSystemResource(name))

               // set other properties on the reader

}


查看完整回答
反對 回復 2022-06-15
?
ibeautiful

TA貢獻1993條經驗 獲得超6個贊

使用 Spring,您應該能夠通過使用帶有語法的@Value注釋來獲取命令行參數。${}


public void setFileName(@Value("${inputFileName}") final String name) {

    inputFileName = name;

}

顯然,@Value注釋適用于由 Spring 上下文(Beans)管理(有時是代理)的對象。


查看完整回答
反對 回復 2022-06-15
  • 2 回答
  • 0 關注
  • 102 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號