【问题标题】:Spring Batch JobLauncher with Parameters in a Remote Partitioner带有远程分区器参数的 Spring Batch JobLauncher
【发布时间】:2021-07-03 00:22:32
【问题描述】:

我正在将我的 Spring Batch Partitioner 从本地分区 (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,它使用参数启动 Job:

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

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

并以同样的方式启动主服务器。

这是错误堆栈:

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$1.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$$95086da9.CGLIB$setJobLauncher$8(<generated>) ~[classes!/:0.0.1-SNAPSHOT]
    at io.spring.batch.configuration.JobConfiguration$$EnhancerBySpringCGLIB$$95086da9$$FastClassBySpringCGLIB$$1bf34d85.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$$95086da9.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$0(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.

Slave 不会抛出任何错误:

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 集成中缺少一个配置。

感谢任何帮助/领导。谢谢,马库斯。

【问题讨论】:

    标签: spring-batch spring-integration


    【解决方案1】:

    我想给 Job 传递一个参数

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

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

    所以我将@Profile 移动到@Bean,它使用参数启动作业:

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

    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);
    }
    

    这个 sn-p 意味着您在应用程序上下文中定义了一个 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

    【讨论】:

    • 我没有提到我想动态传递作业参数,这就是为什么我在运行 jar (java -jar myjob.jar param1=value1 param2 =值2)。然后我将不得不去定义 bean jobLauncher() 的路线并在那里添加参数。
    • 在该方法中传递它们是没有意义的,因为该方法是在配置时调用的。作业参数在运行时传递。
    • 那我有什么选择呢?添加一个 CommandLineRunner 并使用参数触发 JobExecution?我不是这个选项的忠实拥护者,因为那样我将不得不创建一个单独的 jar,它使用 CommandLineRunner 为 master 运行从属和 anotger。
    • 您可以在命令行中将作业参数作为键/值对传递,如答案所示。
    猜你喜欢
    • 2019-04-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-31
    • 2020-10-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多