Search code examples
javaspringspring-integrationnoclassdeffounderrortomcat9

Spring integration handler fails with NoClassDefFoundError for ClassUtils


There is a Spring 5 application being deplpoyed as *.war into Tomcat 9. The app depends on org.springframework.integration:spring-integration-jms:5.4.13 and has one endpoint.

@RestController
class MyController {

    private final MessageChannel channel;

    public IntegrationChannelDataloadingResource(MessageChannel myChannel){
        this.channel = channel;
    }

    @GetMapping("/send-message")
    public void sendMessage(){
        Message m = Helper.createDummyMessage();

        channel.send(m);
    }
}

Invocation of this endpoint produces NoClassDefFoundError for org.springframework.integration.util.ClassUtils (see stacktrace below)

This class is definitely in the classpath and presumably a cause of this error is this class's failing static initialization block (see on GitHub), although no visible evidence for that in logs.

I am trying to find what usually causes such failures for Spring internal classes and what possibly this application lacks for normal initilization. How to investigate this problem?

Stacktrace:

Caused by: java.lang.NoClassDefFoundError: Could not initialize class org.s.integration.util.ClassUtils
  at org.s.integration.handler.support.MessagingMethodInvokerHelper$HandlerMethod.invoke(MessagingMethodInvokerHelper.java:1107)
  at org.s.integration.handler.support.MessagingMethodInvokerHelper.invokeHandlerMethod(MessagingMethodInvokerHelper.java:583)
  at org.s.integration.handler.support.MessagingMethodInvokerHelper.processInternal(MessagingMethodInvokerHelper.java:478)
  at org.s.integration.handler.support.MessagingMethodInvokerHelper.process(MessagingMethodInvokerHelper.java:356)
  at org.s.integration.handler.MethodInvokingMessageProcessor.processMessage(MethodInvokingMessageProcessor.java:108)
  at org.s.integration.transformer.AbstractMessageProcessingTransformer.transform(AbstractMessageProcessingTransformer.java:115)
  at org.s.integration.transformer.MessageTransformingHandler.handleRequestMessage(MessageTransformingHandler.java:119)
  at org.s.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:134)
  at org.s.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:56)
  at org.s.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:115)
  at org.s.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:133)
  at org.s.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:106)
  at org.s.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:72)
  at org.s.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:317)
  at org.s.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:272)
  at app.domain.resources.MyController.sendMessage(....)

Solution

  • See this fixed issue for more info : https://github.com/spring-projects/spring-integration/issues/3875. In general this is not a problem of the class, but multi-class loader application . It might very possible that your controller is loaded with web class loader , but that ClassUtils expectations are in other non-web class path .