작업 매개 변수를 사용자 정의 ItemReader에 주입하려고합니다. 제목 (예 : How to get access to job parameters from ItemReader, in Spring Batch?)에 대한 StackOverflow 노트를 모두 검토했으며, 이것이 대부분 해결되지 않은 공통된 문제점이라고 생각합니다. 나는 봄의 구루 (@Michael Minella 누구)가 이것을보고 약간의 통찰력을 가지기를 바라고있다.스프링 배치의 JobParameters
필자는 코드 나 구성 변경 없이도 작업 실행 수가 10 회 중 1 회 정도 사용할 수 있다고 판단했습니다. 이것은 임의의 실패가 아닌 임의의 성공의 경우이므로 추적하기가 어렵습니다.
디버거를 사용하여 스프링 코드를 파고 이것이 실패 할 때 주입이 발생하는 시점에 jobParameters라는 이름의 빈이 Spring에 등록되지 않았 음을 확인했습니다.
나는 자바에서 실행, 스프링 배치 3.0.2 및 스프링 데이터 JPA 1.7.1 및 스프링 데이터 공유지 1.9.1로 8
자바 클래스
을 봄 4.1.4를 사용하고 있습니다@Component("sourceSelectionReader")
@Scope("step")
public class SourceSelectionReaderImpl
implements ItemReader<MyThing> {
private Map<String,Object> jobParameters;
// ... snip ...
@Autowired
@Lazy
@Qualifier(value="#{jobParameters}")
public void setJobParameters(Map<String, Object> jobParameters) {
this.jobParameters = jobParameters;
}
}
작업 시작 매개 변수 :
launch-context.xml job1 jobid(long)=1
출시-context.xml에 (마이너스 보풀) :
<context:property-placeholder location="classpath:batch.properties" />
<context:component-scan base-package="com.maxis.maximo.ilm" />
<jdbc:initialize-database data-source="myDataSource" enabled="false">
<jdbc:script location="${batch.schema.script}" />
</jdbc:initialize-database>
<batch:job-repository id="jobRepository"
data-source="myDataSource"
transaction-manager="transactionManager"
isolation-level-for-create="DEFAULT"
max-varchar-length="1000"/>
<import resource="classpath:/META-INF/spring/module-context.xml" />
,
모듈-context.xml에 (마이너스 보풀) :
<description>Example job to get you started. It provides a skeleton for a typical batch application.</description>
<import resource="classpath:/META-INF/spring/hibernate-context.xml"/>
<import resource="classpath:/META-INF/spring/myapp-context.xml"/>
<context:component-scan base-package="com.me" />
<bean class="org.springframework.batch.core.scope.StepScope" />
<batch:job id="job1">
<batch:step id="step0002" >
<batch:tasklet transaction-manager="transactionManager" start-limit="100" >
<batch:chunk reader="sourceSelectionReader" writer="selectedDataWriter" commit-interval="1" />
</batch:tasklet>
</batch:step>
</batch:job>
어떻게 작업을 시작합니까? – wassgren
그리고 왜 주사에'@ Lazy'를 사용하고 있습니까? 그것은 당신의 작업에 필요한 것입니까? – wassgren
일식 IDE 내에서 작업을 시작합니다. 실행시 명령 줄에서 시작됩니다. @Lazy를 사용하면이 문제를 회피하고 실제 프로젝트를 진행하면서 해결할 수 있기 때문에 사용할 수 있습니다. 빈에 매개 변수를 가져 오는 다른 방법이 있지만 장기적으로 지원 문제가 발생합니다. –