Spring Batchの戻り値を取れずにクソレベルにハマった
単純に、Shellからjavaコマンドでバッチを起動して、$?で取りたかっただけ
ExitStatusをグリグリ弄ったところでうまくいかない、結局、中のコード見たら、BatchStatusと何かの関連で決まるようなコードを見かけたので
module-context.xmlあたりにSimpleJvmExitCodeMapperのbeanを突っ込んで
<!-- exitCodeMapper --> <bean class="org.springframework.batch.core.launch.support.SimpleJvmExitCodeMapper" id="exitCodeMapper"/>
@Autowiredした
public class KusoTasklet implements Tasklet, InitializingBean { @Autowired private SimpleJvmExitCodeMapper sm; ...
で、@Autowiredしたクラスあたりで、ExitStatus.COMPLETEDの値を書き換える
... protected void setResultCode(Integer result) { Map<String, Integer> exitCodeMap = new HashMap<String, Integer>(); exitCodeMap.put(ExitStatus.COMPLETED.getExitCode(), result); sm.setMapping(exitCodeMap); } ...
やってみた
cuomo@ugui7 ~/workspace/batchkoi/target $ java -cp ./dependency/*:./spring-batch-kuso-2.0.0.CI-SNAPSHOT.jar org.springframework.batch.core.launch.support.CommandLineJobRunner launch-context.xml kusoGoodJob 2017-04-23 20:28:31,123 INFO [org.springframework.context.support.ClassPathXmlApplicationContext] - <Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@2a33fae0: startup date [Sun Apr 23 20:28:31 JST 2017]; root of context hierarchy> 2017-04-23 20:28:31,147 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from class path resource [launch-context.xml]> 2017-04-23 20:28:31,275 INFO [org.springframework.beans.factory.xml.XmlBeanDefinitionReader] - <Loading XML bean definitions from class path resource [META-INF/spring/module-context.xml]> ... ... ... 2017-04-23 20:28:32,778 INFO [org.springframework.beans.factory.support.DefaultListableBeanFactory] - <Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@42eca56e: defining beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,eroUserServiceImpl,reader,writer,exampleConfiguration,org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,org.springframework.batch.core.scope.internalStepScope,org.springframework.beans.factory.config.CustomEditorConfigurer,org.springframework.batch.core.configuration.xml.CoreNamespacePostProcessor,jobRepository,exitCodeMapper,step_kuso,kuso,kuso_Tasklet,step2,job1,fileDeletingTasklet,org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#1,org.springframework.aop.config.internalAutoProxyCreator,org.springframework.transaction.annotation.AnnotationTransactionAttributeSource#0,org.springframework.transaction.interceptor.TransactionInterceptor#0,org.springframework.transaction.config.internalTransactionAdvisor,eroUserMapper,dataSource,transactionManager,sqlSessionFactory,org.dozer.spring.DozerBeanMapperFactoryBean#0,jobLauncher]; root of factory hierarchy> 2017-04-23 20:28:32,780 INFO [org.dozer.jmx.JMXPlatformImpl] - <Unregistering existing Dozer JMX MBean [org.dozer.jmx:type=DozerAdminController].> 2017-04-23 20:28:32,780 INFO [org.dozer.jmx.JMXPlatformImpl] - <Unregistering existing Dozer JMX MBean [org.dozer.jmx:type=DozerStatisticsController].> cuomo@ugui7 ~/workspace/batchkoi/target $ echo $? 99 cuomo@ugui7 ~/workspace/batchkoi/target $
resultへ任意の数字を仕込めばshellの戻り値になる
ググったら、ここに 書いてあるじゃないか。。。
なかのコード見てる暇あったら、みんなググロー、1日無駄になった...
0 件のコメント:
コメントを投稿