I have been using Spring integration (different types of channels) with Spring 4 for some time. After i tried to upgrade my environment to Spring 5, they stopped working with errors such as the following:
org.springframework.messaging.MessageHandlingException: error occurred during processing message in 'MethodInvokingMessageProcessor' [org.springframework.integration.handler.MethodInvokingMessageProcessor@c192373]; nested exception is java.lang.IllegalArgumentException: BeanFactory must not be null, failedMessage=GenericMessage
Sample channel creation/registration is as follows:
deltaupdatedchannel = new DirectChannel(); deltaupdatedchannel.setBeanName("deltaupdatedcontroller");
serviceActivator = new ServiceActivatingHandler(deltaSummaryController, "updateDelta2");
handlerlist.add(serviceActivator);
beanFactory.registerSingleton("deltaupdatedcontroller", deltaupdatedchannel);
beanFactory.initializeBean(deltaupdatedchannel, "deltaupdatedcontroller");
deltaupdatedchannel.subscribe(serviceActivator);
Channels are used to make the following call: this.deltaupdatedcontrollerchannel.send(MessageBuilder.withPayload(summarydto).build());
And channel calls the following code:
public void updateDelta2(DeltaSummaryDTO dto) {
this.messagingTemplate.convertAndSend(
"/topic/updatedelta", dto);
}
Here messagingTemplate is org.springframework.messaging.core.MessageSendingOperations.
How can i make them work again?
CodePudding user response:
Share, please, with us the reason doing that registerSingleton()
. Why just plain bean registration is not enough for you?
To fix that problem you need to call also initializeBean(Object existingBean, String beanName)
after that registerSingleton()
.
However there is no guarantee that this will be the end of errors. I would suggest to revise a design in favor of normal bean definitions, not that manual one...