>

원격 파티셔닝을 위해 작업을 구성했고, kafka를 통해 메시지를 보내는데, 슬레이브 VM이 요청을 수신하고 단계를 시작하려고하지만 단계를 찾을 수 없습니다.

제공하는 beanFactory (applicationContext)에 원격 실행 단계가 포함되어 있지 않은 것 같습니다.

https://www.youtube.com/watch?에서 예제를 살펴 보았습니다. v = CYTj5YT7CZU 여러 번 , 올바른 beanFactory가 슬레이브 작업에 대해 식별되고 설정되는 방법이 누락되었습니다.

애플리케이션 초기화 중에 ClasspathXmlApplicationContextsFactoryBean은 모든 스프링 배치 작업 및 원격 슬레이브 단계에 대한 XML을 포함하는 작업 라이브러리에서로드됩니다. 이 Bean에는 슬레이브 파일 (예상대로)을 포함하여 applicationContext에 할당 된 각 XML 파일에 대한 별도의 리소스가 포함되어 있습니다.

@Bean
public ClasspathXmlApplicationContextsFactoryBean classpathXmlApplicationContextsFactoryBean () throws IOException
{
    String resourcePath = configPropertiesService
            .fetchPropertyValue(PropertyValueConstants.MXARCHIVE_SKELETON_LOCATION,
                    PropertyValueConstants.MXARCHIVE_SKELETON_LOCATION_DEFAULT)
            .getValue() + "*.xml";
    logger.trace("classpathXmlApplicationContextsFactoryBean()  :: {} ", resourcePath);
    Resource[] resources = applicationContext.getResources(resourcePath);
    ClasspathXmlApplicationContextsFactoryBean bean = new ClasspathXmlApplicationContextsFactoryBean ();
    bean.setApplicationContext(applicationContext);
    bean.setResources(resources);
    return bean;
}

BeanFactoryStepLocator는 applicationContext로 초기화됩니다.

@Bean
public BeanFactoryStepLocator stepLocator() throws Exception
{
    BeanFactoryStepLocator stepLocator = new BeanFactoryStepLocator ();
/* applicationContext is autowired in the postconstruct - what we do here doesn't matter
    stepLocator.setBeanFactory(applicationContext); // TODO: Find the right factory
    */
    return stepLocator;
};
// EDIT: added method to code listing so the calling method is visible
@Bean
public StepExecutionRequestHandler stepExecutionRequestHandler() throws Exception {
    StepExecutionRequestHandler result = new StepExecutionRequestHandler();
    ;
    result.setJobExplorer(jobExplorer);
    BeanFactoryStepLocator stepLocator = stepLocator ();
    result.setStepLocator(stepLocator);
    return result;
}

실행시 프레임 워크는 단계를 호출하려고 시도하고 애플리케이션 컨텍스트 (beanFactory)에 단계가 없으므로 실패합니다.

Thread-7 2019-04-23 12:47:30,343 INFO  c.m.m.s.DefaultBatchConfigurer - ThreadPoolTaskExecutor status => Active threads :: 1, Total threads ::30, 3.3333333333333335 % Active.
executionContainer-C-1 2019-04-23 12:47:30,966 ERROR o.s.k.l.LoggingErrorHandler - Error while processing: ConsumerRecord(topic = job.step, partition = 0, offset = 47, CreateTime = 1556041503162, serialized key size = 4, serialized value size = 78, headers = RecordHeaders(headers = [RecordHeader(key = sequenceNumber, value = [49, 49]), RecordHeader(key = correlationId, value = [34, 49, 55, 57, 49, 58, 102, 115, 45, 115, 116, 101, 112, 48, 48, 48, 50, 46, 115, 108, 97, 118, 101, 34]), RecordHeader(key = sequenceSize, value = [49, 50]), RecordHeader(key = spring_json_header_types, value = [123, 34, 115, 101, 113, 117, 101, 110, 99, 101, 78, 117, 109, 98, 101, 114, 34, 58, 34, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 73, 110, 116, 101, 103, 101, 114, 34, 44, 34, 115, 101, 113, 117, 101, 110, 99, 101, 83, 105, 122, 101, 34, 58, 34, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 73, 110, 116, 101, 103, 101, 114, 34, 44, 34, 99, 111, 114, 114, 101, 108, 97, 116, 105, 111, 110, 73, 100, 34, 58, 34, 106, 97, 118, 97, 46, 108, 97, 110, 103, 46, 83, 116, 114, 105, 110, 103, 34, 125])], isReadOnly = false), key = 11, value = StepExecutionRequest: [jobExecutionId=1791, stepExecutionId=21396, stepName=fs-step0002.slave])
org.springframework.messaging.MessageHandlingException: nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'fs-step0002.slave' available
    at org.springframework.integration.handler.MethodInvokingMessageProcessor.processMessage(MethodInvokingMessageProcessor.java:109) ~[spring-integration-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.integration.handler.ServiceActivatingHandler.handleRequestMessage(ServiceActivatingHandler.java:93) ~[spring-integration-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:123) ~[spring-integration-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:169) ~[spring-integration-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:115) ~[spring-integration-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:132) ~[spring-integration-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:105) ~[spring-integration-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:73) ~[spring-integration-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:461) ~[spring-integration-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:401) ~[spring-integration-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:187) ~[spring-messaging-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:166) ~[spring-messaging-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:47) ~[spring-messaging-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.messaging.core.AbstractMessageSendingTemplate.send(AbstractMessageSendingTemplate.java:109) ~[spring-messaging-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.integration.endpoint.MessageProducerSupport.sendMessage(MessageProducerSupport.java:205) ~[spring-integration-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.integration.kafka.inbound.KafkaMessageDrivenChannelAdapter.sendMessageIfAny(KafkaMessageDrivenChannelAdapter.java:369) ~[spring-integration-kafka-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.integration.kafka.inbound.KafkaMessageDrivenChannelAdapter.access$400(KafkaMessageDrivenChannelAdapter.java:74) ~[spring-integration-kafka-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.integration.kafka.inbound.KafkaMessageDrivenChannelAdapter$IntegrationRecordMessageListener.onMessage(KafkaMessageDrivenChannelAdapter.java:431) ~[spring-integration-kafka-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.integration.kafka.inbound.KafkaMessageDrivenChannelAdapter$IntegrationRecordMessageListener.onMessage(KafkaMessageDrivenChannelAdapter.java:402) ~[spring-integration-kafka-3.1.1.RELEASE.jar:3.1.1.RELEASE]
    at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doInvokeOnMessage(KafkaMessageListenerContainer.java:1224) [spring-kafka-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeOnMessage(KafkaMessageListenerContainer.java:1217) [spring-kafka-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doInvokeRecordListener(KafkaMessageListenerContainer.java:1178) [spring-kafka-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.doInvokeWithRecords(KafkaMessageListenerContainer.java:1159) [spring-kafka-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeRecordListener(KafkaMessageListenerContainer.java:1099) [spring-kafka-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.invokeListener(KafkaMessageListenerContainer.java:934) [spring-kafka-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.pollAndInvoke(KafkaMessageListenerContainer.java:750) [spring-kafka-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at org.springframework.kafka.listener.KafkaMessageListenerContainer$ListenerConsumer.run(KafkaMessageListenerContainer.java:699) [spring-kafka-2.2.4.RELEASE.jar:2.2.4.RELEASE]
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_162]
    at java.util.concurrent.FutureTask.run(FutureTask.java:266) [na:1.8.0_162]
    at java.lang.Thread.run(Thread.java:748) [na:1.8.0_162]
Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'fs-step0002.slave' available
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanDefinition(DefaultListableBeanFactory.java:772) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getMergedLocalBeanDefinition(AbstractBeanFactory.java:1221) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:294) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) ~[spring-beans-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.batch.integration.partition.BeanFactoryStepLocator.getStep(BeanFactoryStepLocator.java:34) ~[spring-batch-integration-4.1.1.RELEASE.jar:4.1.1.RELEASE]
    at org.springframework.batch.integration.partition.StepExecutionRequestHandler.handle(StepExecutionRequestHandler.java:58) ~[spring-batch-integration-4.1.1.RELEASE.jar:4.1.1.RELEASE]
    at sun.reflect.GeneratedMethodAccessor687.invoke(Unknown Source) ~[na:na]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_162]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_162]
    at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:170) ~[spring-messaging-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.messaging.handler.invocation.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:120) ~[spring-messaging-5.1.5.RELEASE.jar:5.1.5.RELEASE]
    at org.springframework.integration.handler.support.MessagingMethodInvokerHelper$HandlerMethod.invoke(MessagingMethodInvokerHelper.java:1119) ~[spring-integration-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.invokeHandlerMethod(MessagingMethodInvokerHelper.java:617) ~[spring-integration-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.processInternal(MessagingMethodInvokerHelper.java:490) ~[spring-integration-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.integration.handler.support.MessagingMethodInvokerHelper.process(MessagingMethodInvokerHelper.java:313) ~[spring-integration-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    at org.springframework.integration.handler.MethodInvokingMessageProcessor.processMessage(MethodInvokingMessageProcessor.java:106) ~[spring-integration-core-5.1.3.RELEASE.jar:5.1.3.RELEASE]
    ... 29 common frames omitted

단계 XML (위생)은 다음과 같습니다.

<?xml version="1.0" encoding="UTF-8"?>
<beans default-lazy-init="false" > <!-- usual suspects -->
    <bean class="org.springframework.batch.core.scope.JobScope">
        <property name="proxyTargetClass" value="true" />
    </bean>
    <bean class="org.springframework.batch.core.scope.StepScope">
        <property name="proxyTargetClass" value="true" />
    </bean>
    <batch:step id="fs-step0002.slave">
        <batch:tasklet transaction-manager="jtaTransactionManager"
            start-limit="100">
            <batch:chunk reader="myCustomItemReader" writer="myCustomWriter"
                commit-interval="1"/>
        </batch:tasklet>
        <batch:fail on="FAILED" />
    </batch:step>
</beans>

편집 1 :

원격 단계 파일 만 읽고 새 ClasspathXmlApplicationContextsFactoryBean을 작성했습니다 (하나만). 여전히 예상되는 이름의 콩이 없다고 불평하지만 분명히 거기에 있음을 알 수 있습니다.

나중에 steplocator를 추적 할 때 beanFactory가 비어 있음을 알 수 있습니다.

테스트를위한 대안 코드 :

@Bean
public ClasspathXmlApplicationContextsFactoryBean stepFactoryBean() throws IOException {
    String resourcePath = configPropertiesService
            .fetchPropertyValue(PropertyValueConstants.MXARCHIVE_SKELETON_LOCATION,
                    PropertyValueConstants.MXARCHIVE_SKELETON_LOCATION_DEFAULT)
            .getValue() + "*slave.xml";
    logger.trace("classpathXmlApplicationContextsFactoryBean()  :: {} ", resourcePath);
    Resource[] resources = applicationContext.getResources(resourcePath);
    ClasspathXmlApplicationContextsFactoryBean bean = new ClasspathXmlApplicationContextsFactoryBean();
    bean.setApplicationContext(applicationContext);
    bean.setResources(resources);
    return bean;
}
@Bean
public BeanFactoryStepLocator stepLocator() throws Exception {
    BeanFactoryStepLocator stepLocator = new BeanFactoryStepLocator();
    ApplicationContextFactory[] factories = stepFactoryBean().getObject();
    if (factories != null) {         
        stepLocator.setBeanFactory(factories[0].createApplicationContext().getBeanFactory());
    }
    return stepLocator;
};

만들 때 stepLocator 내에서 beanFactory의 디버거보기.

디버거 stepLocator () 팩토리 메소드 종료시 getStep () 결과보기 :

편집 2 :

원래의 "applicationContext"가 beanfactory로 자동 연결되어 있기 때문에 실제 문제는 추가 bean을 applicationContext에로드하는 것입니다.

또한 런타임에 봄에 추가 Bean 구성 파일을로드하는 방법 및 링크 된 질문.

  • 답변 # 1

    BeanFactory에 필요한 의존성을 선언하고 Spring이 조회/주입을 수동으로 수행하는 대신 올바른 인스턴스를 제공하도록 할 수있다. 따라서 대신 :

    @Bean
    public BeanFactoryStepLocator stepLocator() throws Exception {
       BeanFactoryStepLocator stepLocator = new BeanFactoryStepLocator();
       ApplicationContextFactory[] factories = stepFactoryBean().getObject();
       if (factories != null) {         
          stepLocator.setBeanFactory(factories[0].createApplicationContext().getBeanFactory());
       }
       return stepLocator;
    };
    
    

    다음과 같은 것을 사용하십시오 :

    @Bean
    public StepLocator stepLocator(BeanFactory beanFactory) {
        BeanFactoryStepLocator beanFactoryStepLocator = new BeanFactoryStepLocator();
        beanFactoryStepLocator.setBeanFactory(beanFactory);
        return beanFactoryStepLocator;
    }
    
    

    이것이 도움이되기를 바랍니다.

관련 자료

  • 이전 dataframe - rhandsontable r 패키지를 사용하여 편집 한 내용을 저장하는 방법
  • 다음 javascript - UI 라우터를 사용하여 객체를 상태로 전달하는 방법은 무엇입니까?