Spring 在远程分区程序中使用参数批处理 JobLauncher

Spring Batch JobLauncher with Parameters in a Remote Partitioner

我正在将 Spring 批处理分区程序从本地分区 (ThreadPool) 移动到远程分区。

我开始研究@Michael Minella 发布的模式https://github.com/mminella/LearningSpringBatch/tree/master/src/remotePartitioning

在他的例子中,他启动了奴隶:

java -jar -Dspring.profiles.active=slave target/remote-partitioning-0.0.1-SNAPSHOT.jar

大师与:

java -jar -Dspring.profiles.active=master target/remote-partitioning-0.0.1-SNAPSHOT.jar

现在,我想将一个参数传递给 Job,所以我将 @Profile 移动到一个使用参数启动该作业的 @Bean:

@Bean
@Profile("master")
public JobExecution setJobLauncher() throws Exception {
    JobParameters jobParameters = new JobParametersBuilder()
            .addLong("time", System.currentTimeMillis()).toJobParameters();

    return jobLauncher.run(job(), jobParameters);
}

并以同样的方式启动 master。

这是错误堆栈:

2021-07-02 20:00:14.336  INFO 44013 --- [           main] i.s.batch.RemotePartitioningApplication  : Starting RemotePartitioningApplication v0.0.1-SNAPSHOT on markus-p51 with PID 44013 (/home/markus/Documents/LearningSpringBatch-master/src/remotePartitioning/target/remote-partitioning-0.0.1-SNAPSHOT.jar started by markus in /home/markus/Documents/LearningSpringBatch-master/src/remotePartitioning)
2021-07-02 20:00:14.339  INFO 44013 --- [           main] i.s.batch.RemotePartitioningApplication  : The following profiles are active: master
2021-07-02 20:00:15.096  INFO 44013 --- [           main] faultConfiguringBeanFactoryPostProcessor : No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
2021-07-02 20:00:15.100  INFO 44013 --- [           main] faultConfiguringBeanFactoryPostProcessor : No bean named 'taskScheduler' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.
2021-07-02 20:00:15.106  INFO 44013 --- [           main] faultConfiguringBeanFactoryPostProcessor : No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created.
2021-07-02 20:00:15.179  INFO 44013 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'integrationChannelResolver' of type [org.springframework.integration.support.channel.BeanFactoryChannelResolver] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-07-02 20:00:15.308  INFO 44013 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'integrationDisposableAutoCreatedBeans' of type [org.springframework.integration.config.annotation.Disposables] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-07-02 20:00:15.330  INFO 44013 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.integration.config.IntegrationManagementConfiguration' of type [org.springframework.integration.config.IntegrationManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2021-07-02 20:00:16.230  INFO 44013 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2021-07-02 20:00:16.235  WARN 44013 --- [           main] com.zaxxer.hikari.util.DriverDataSource  : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
2021-07-02 20:00:16.510  INFO 44013 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2021-07-02 20:00:16.521  INFO 44013 --- [           main] o.s.b.c.r.s.JobRepositoryFactoryBean     : No database type set, using meta data indicating: MYSQL
2021-07-02 20:00:16.713  INFO 44013 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : No TaskExecutor has been set, defaulting to synchronous executor.
2021-07-02 20:00:16.837  INFO 44013 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [SimpleJob: [name=job]] launched with the following parameters: [{time=1625270416098}]
2021-07-02 20:00:16.910  INFO 44013 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step1]
2021-07-02 20:00:16.986 ERROR 44013 --- [           main] o.s.batch.core.step.AbstractStep         : Encountered an error executing step step1 in job job

org.springframework.messaging.MessageDeliveryException: Dispatcher has no subscribers for channel 'application.outboundRequests'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers, failedMessage=GenericMessage [payload=StepExecutionRequest: [jobExecutionId=31, stepExecutionId=54, stepName=slaveStep], headers={sequenceNumber=0, correlationId=31:slaveStep, id=effa1b0a-e074-5417-105e-48e8f959cd3b, sequenceSize=4, timestamp=1625270416981}]
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:76) ~[spring-integration-core-5.3.2.RELEASE.jar!/:5.3.2.RELEASE]
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:578) ~[spring-integration-core-5.3.2.RELEASE.jar!/:5.3.2.RELEASE]
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:520) ~[spring-integration-core-5.3.2.RELEASE.jar!/:5.3.2.RELEASE]
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:187) ~[spring-messaging-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:166) ~[spring-messaging-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:47) ~[spring-messaging-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:109) ~[spring-messaging-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:99) ~[spring-messaging-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.batch.integration.partition.MessageChannelPartitionHandler.handle(MessageChannelPartitionHandler.java:228) ~[spring-batch-integration-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
    at org.springframework.batch.core.partition.support.PartitionStep.doExecute(PartitionStep.java:106) ~[spring-batch-core-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
    at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:208) ~[spring-batch-core-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
    at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148) ~[spring-batch-core-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
    at org.springframework.batch.core.job.AbstractJob.handleStep(AbstractJob.java:410) ~[spring-batch-core-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
    at org.springframework.batch.core.job.SimpleJob.doExecute(SimpleJob.java:136) ~[spring-batch-core-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
    at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:319) ~[spring-batch-core-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
    at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:147) ~[spring-batch-core-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
    at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) ~[spring-core-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:140) ~[spring-batch-core-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344) ~[spring-aop-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198) ~[spring-aop-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:127) ~[spring-batch-core-4.2.4.RELEASE.jar!/:4.2.4.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) ~[spring-aop-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at com.sun.proxy.$Proxy45.run(Unknown Source) ~[na:na]
    at io.spring.batch.configuration.JobConfiguration.setJobLauncher(JobConfiguration.java:121) ~[classes!/:0.0.1-SNAPSHOT]
    at io.spring.batch.configuration.JobConfiguration$$EnhancerBySpringCGLIB$086da9.CGLIB$setJobLauncher(<generated>) ~[classes!/:0.0.1-SNAPSHOT]
    at io.spring.batch.configuration.JobConfiguration$$EnhancerBySpringCGLIB$086da9$$FastClassBySpringCGLIB$bf34d85.invoke(<generated>) ~[classes!/:0.0.1-SNAPSHOT]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:244) ~[spring-core-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:331) ~[spring-context-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at io.spring.batch.configuration.JobConfiguration$$EnhancerBySpringCGLIB$086da9.setJobLauncher(<generated>) ~[classes!/:0.0.1-SNAPSHOT]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:650) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:483) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1336) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1176) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean[=14=](AbstractBeanFactory.java:324) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:322) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:897) ~[spring-beans-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:879) ~[spring-context-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:551) ~[spring-context-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.3.3.RELEASE.jar!/:2.3.3.RELEASE]
    at io.spring.batch.RemotePartitioningApplication.main(RemotePartitioningApplication.java:14) ~[classes!/:0.0.1-SNAPSHOT]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49) ~[remote-partitioning-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:109) ~[remote-partitioning-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:58) ~[remote-partitioning-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:88) ~[remote-partitioning-0.0.1-SNAPSHOT.jar:0.0.1-SNAPSHOT]
Caused by: org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:139) ~[spring-integration-core-5.3.2.RELEASE.jar!/:5.3.2.RELEASE]
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:106) ~[spring-integration-core-5.3.2.RELEASE.jar!/:5.3.2.RELEASE]
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:72) ~[spring-integration-core-5.3.2.RELEASE.jar!/:5.3.2.RELEASE]
    ... 67 common frames omitted

2021-07-02 20:00:16.991  INFO 44013 --- [           main] o.s.batch.core.step.AbstractStep         : Step: [step1] executed in 81ms
2021-07-02 20:00:17.010  INFO 44013 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [SimpleJob: [name=job]] completed with the following parameters: [{time=1625270416098}] and the following status: [FAILED] in 131ms
2021-07-02 20:00:17.197  INFO 44013 --- [           main] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService 'taskScheduler'
2021-07-02 20:00:17.248  INFO 44013 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2021-07-02 20:00:17.248  INFO 44013 --- [           main] o.s.i.channel.PublishSubscribeChannel    : Channel 'application.errorChannel' has 1 subscriber(s).
2021-07-02 20:00:17.248  INFO 44013 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started bean '_org.springframework.integration.errorLogger'
2021-07-02 20:00:17.248  INFO 44013 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : Adding {amqp:outbound-gateway:integrationConfiguration.amqpOutboundEndpoint.serviceActivator} as a subscriber to the 'outboundRequests' channel
2021-07-02 20:00:17.248  INFO 44013 --- [           main] o.s.integration.channel.DirectChannel    : Channel 'application.outboundRequests' has 1 subscriber(s).
2021-07-02 20:00:17.248  INFO 44013 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started bean 'integrationConfiguration.amqpOutboundEndpoint.serviceActivator'
2021-07-02 20:00:17.260  INFO 44013 --- [           main] i.s.batch.RemotePartitioningApplication  : Started RemotePartitioningApplication in 3.349 seconds (JVM running for 3.881)
2021-07-02 20:00:17.261  INFO 44013 --- [           main] o.s.b.a.b.JobLauncherApplicationRunner   : Running default command line with: []
2021-07-02 20:00:17.340  INFO 44013 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [SimpleJob: [name=job]] launched with the following parameters: [{}]
2021-07-02 20:00:17.355  INFO 44013 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Step already complete or not restartable, so no action to execute: StepExecution: id=12, version=2, name=step1, status=COMPLETED, exitStatus=COMPLETED, readCount=100000, filterCount=0, writeCount=100000 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=104, rollbackCount=0, exitDescription=
2021-07-02 20:00:17.363  INFO 44013 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [SimpleJob: [name=job]] completed with the following parameters: [{}] and the following status: [COMPLETED] in 15ms
2021-07-02 20:00:17.371  INFO 44013 --- [extShutdownHook] o.s.i.endpoint.EventDrivenConsumer       : Removing {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2021-07-02 20:00:17.371  INFO 44013 --- [extShutdownHook] o.s.i.channel.PublishSubscribeChannel    : Channel 'application.errorChannel' has 0 subscriber(s).
2021-07-02 20:00:17.371  INFO 44013 --- [extShutdownHook] o.s.i.endpoint.EventDrivenConsumer       : stopped bean '_org.springframework.integration.errorLogger'
2021-07-02 20:00:17.371  INFO 44013 --- [extShutdownHook] o.s.i.endpoint.EventDrivenConsumer       : Removing {amqp:outbound-gateway:integrationConfiguration.amqpOutboundEndpoint.serviceActivator} as a subscriber to the 'outboundRequests' channel
2021-07-02 20:00:17.371  INFO 44013 --- [extShutdownHook] o.s.integration.channel.DirectChannel    : Channel 'application.outboundRequests' has 0 subscriber(s).
2021-07-02 20:00:17.371  INFO 44013 --- [extShutdownHook] o.s.i.endpoint.EventDrivenConsumer       : stopped bean 'integrationConfiguration.amqpOutboundEndpoint.serviceActivator'
2021-07-02 20:00:17.372  INFO 44013 --- [extShutdownHook] o.s.s.c.ThreadPoolTaskScheduler          : Shutting down ExecutorService 'taskScheduler'
2021-07-02 20:00:17.373  INFO 44013 --- [extShutdownHook] o.s.a.r.l.SimpleMessageListenerContainer : Shutdown ignored - container is not active already
2021-07-02 20:00:17.375  INFO 44013 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2021-07-02 20:00:17.383  INFO 44013 --- [extShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.

从站没有抛出任何错误:

2021-07-02 20:17:58.894  INFO 45764 --- [           main] i.s.batch.RemotePartitioningApplication  : Starting RemotePartitioningApplication v0.0.1-SNAPSHOT on markus-p51 with PID 45764 (/home/markus/Documents/LearningSpringBatch-master/src/remotePartitioning/target/remote-partitioning-0.0.1-SNAPSHOT.jar started by markus in /home/markus/Documents/LearningSpringBatch-master/src/remotePartitioning)
2021-07-02 20:17:58.898  INFO 45764 --- [           main] i.s.batch.RemotePartitioningApplication  : The following profiles are active: slave
2021-07-02 20:17:59.616  INFO 45764 --- [           main] faultConfiguringBeanFactoryPostProcessor : No bean named 'errorChannel' has been explicitly defined. Therefore, a default PublishSubscribeChannel will be created.
2021-07-02 20:17:59.619  INFO 45764 --- [           main] faultConfiguringBeanFactoryPostProcessor : No bean named 'taskScheduler' has been explicitly defined. Therefore, a default ThreadPoolTaskScheduler will be created.
2021-07-02 20:17:59.624  INFO 45764 --- [           main] faultConfiguringBeanFactoryPostProcessor : No bean named 'integrationHeaderChannelRegistry' has been explicitly defined. Therefore, a default DefaultHeaderChannelRegistry will be created.
2021-07-02 20:17:59.685  INFO 45764 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'integrationChannelResolver' of type [org.springframework.integration.support.channel.BeanFactoryChannelResolver] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-07-02 20:17:59.811  INFO 45764 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'integrationDisposableAutoCreatedBeans' of type [org.springframework.integration.config.annotation.Disposables] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2021-07-02 20:17:59.835  INFO 45764 --- [           main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.integration.config.IntegrationManagementConfiguration' of type [org.springframework.integration.config.IntegrationManagementConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary.
2021-07-02 20:18:00.585  INFO 45764 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2021-07-02 20:18:00.590  WARN 45764 --- [           main] com.zaxxer.hikari.util.DriverDataSource  : Registered driver with driverClassName=com.mysql.jdbc.Driver was not found, trying direct instantiation.
2021-07-02 20:18:00.832  INFO 45764 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2021-07-02 20:18:00.895  INFO 45764 --- [           main] o.s.b.c.r.s.JobRepositoryFactoryBean     : No database type set, using meta data indicating: MYSQL
2021-07-02 20:18:01.029  INFO 45764 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : No TaskExecutor has been set, defaulting to synchronous executor.
2021-07-02 20:18:01.143  INFO 45764 --- [           main] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService 'taskScheduler'
2021-07-02 20:18:01.222  INFO 45764 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
2021-07-02 20:18:01.222  INFO 45764 --- [           main] o.s.i.channel.PublishSubscribeChannel    : Channel 'application.errorChannel' has 1 subscriber(s).
2021-07-02 20:18:01.222  INFO 45764 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started bean '_org.springframework.integration.errorLogger'
2021-07-02 20:18:01.222  INFO 45764 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : Adding {amqp:outbound-gateway:integrationConfiguration.amqpOutboundEndpoint.serviceActivator} as a subscriber to the 'outboundRequests' channel
2021-07-02 20:18:01.222  INFO 45764 --- [           main] o.s.integration.channel.DirectChannel    : Channel 'application.outboundRequests' has 1 subscriber(s).
2021-07-02 20:18:01.222  INFO 45764 --- [           main] o.s.i.endpoint.EventDrivenConsumer       : started bean 'integrationConfiguration.amqpOutboundEndpoint.serviceActivator'
2021-07-02 20:18:01.223  INFO 45764 --- [           main] o.s.a.r.c.CachingConnectionFactory       : Attempting to connect to: [localhost:5672]
2021-07-02 20:18:01.300  INFO 45764 --- [           main] o.s.a.r.c.CachingConnectionFactory       : Created new connection: rabbitConnectionFactory#3a5ecce3:0/SimpleConnection@32c0915e [delegate=amqp://guest@127.0.0.1:5672/, localPort= 54076]
2021-07-02 20:18:01.305  INFO 45764 --- [           main] o.s.amqp.rabbit.core.RabbitAdmin         : Auto-declaring a non-durable, auto-delete, or exclusive Queue (partition.requests) durable:false, auto-delete:false, exclusive:false. It will be redeclared if the broker stops and is restarted while the connection factory is alive, but all messages will be lost.
2021-07-02 20:18:01.345  INFO 45764 --- [           main] o.s.i.a.i.AmqpInboundChannelAdapter      : started bean 'inbound'; defined in: 'class path resource [io/spring/batch/configuration/IntegrationConfiguration.class]'; from source: 'org.springframework.core.type.classreading.SimpleMethodMetadata@6107227e'
2021-07-02 20:18:01.347  INFO 45764 --- [           main] o.s.i.endpoint.PollingConsumer           : started bean 'jobConfiguration.stepExecutionRequestHandler.serviceActivator'
2021-07-02 20:18:01.359  INFO 45764 --- [           main] i.s.batch.RemotePartitioningApplication  : Started RemotePartitioningApplication in 2.86 seconds (JVM running for 3.243)
2021-07-02 20:18:01.361  INFO 45764 --- [           main] o.s.b.a.b.JobLauncherApplicationRunner   : Running default command line with: []
2021-07-02 20:18:01.478  INFO 45764 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [SimpleJob: [name=job]] launched with the following parameters: [{}]
2021-07-02 20:18:01.520  INFO 45764 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Step already complete or not restartable, so no action to execute: StepExecution: id=12, version=2, name=step1, status=COMPLETED, exitStatus=COMPLETED, readCount=100000, filterCount=0, writeCount=100000 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=104, rollbackCount=0, exitDescription=
2021-07-02 20:18:01.531  INFO 45764 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [SimpleJob: [name=job]] completed with the following parameters: [{}] and the following status: [COMPLETED] in 25ms

我在尝试将参数传递给 JobLauncher 时是否遗漏了任何设置? Spring 集成中似乎缺少我的配置。

任何 help/lead 表示赞赏。谢谢,马库斯。

I want to pass a parameter to the Job

您可以在命令行上将参数作为 key/value 对传递给作业:

java -jar myjob.jar param1=value1 param2=value2

so I moved the @Profile to a @Bean that launches the job with a parameter:

你不需要这样做,你可以像上面提到的那样将参数传递给作业,比如:

java -jar -Dspring.profiles.active=master target/remote-partitioning-0.0.1-SNAPSHOT.jar time=$(date +%s)

附带说明一下,我想根据此处的代码澄清您似乎存在的困惑:

@Bean
@Profile("master")
public JobExecution setJobLauncher() throws Exception {
    JobParameters jobParameters = new JobParametersBuilder()
            .addLong("time", System.currentTimeMillis()).toJobParameters();

    return jobLauncher.run(job(), jobParameters);
}

此代码段意味着您正在应用程序上下文中定义类型为 JobExecution 的 Spring bean。此 bean 将由 Spring 在 配置 您的应用程序上下文时创建,这对于 运行 工作来说还为时过早。 bean 定义方法应该只配置 bean,比如:

@Bean
public JobLauncher jobLauncher() {
    SimpleJobLauncher jobLauncher = new SimpleJobLauncher();
    // configure the job launcher as needed
    return jobLauncher;
}

顺便说一下,Michael 存储库中的示例使用 @EnableBatchProcessing,它会自动配置 JobLauncher