0

In Spring-MVC you have the ability to remove the Jackson library as a dependency and replace it with your own using this method:

protected void configureMessageConverters(List<HttpMessageConverter<?>> converters)

I am trying to do the same thing for Spring-Websocket so I have overridden both of these methods:

@Bean public CompositeMessageConverter brokerMessageConverter()
protected boolean configureMessageConverters(List<MessageConverter> messageConverters)

However there is still a dependency on Jackson somewhere and I can't figure out where.

EDIT

Here is a stack trace:

Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/databind/JsonMappingException
    at org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService.getDefaultTransportHandlers(DefaultSockJsService.java:81)
    at org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService.<init>(DefaultSockJsService.java:74)
    at org.springframework.web.socket.config.annotation.SockJsServiceRegistration.createSockJsService(SockJsServiceRegistration.java:231)
    at org.springframework.web.socket.config.annotation.SockJsServiceRegistration.getSockJsService(SockJsServiceRegistration.java:198)
    at org.springframework.web.socket.config.annotation.WebMvcStompWebSocketEndpointRegistration$StompSockJsServiceRegistration.getSockJsService(WebMvcStompWebSocketEndpointRegistration.java:113)
    at org.springframework.web.socket.config.annotation.WebMvcStompWebSocketEndpointRegistration.getMappings(WebMvcStompWebSocketEndpointRegistration.java:87)
    at org.springframework.web.socket.config.annotation.WebMvcStompEndpointRegistry.getHandlerMapping(WebMvcStompEndpointRegistry.java:122)
    at org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurationSupport.stompWebSocketHandlerMapping(WebSocketMessageBrokerConfigurationSupport.java:60)
    at com.test.wsb.config.WebsocketConfig$$EnhancerBySpringCGLIB$$b414d315.CGLIB$stompWebSocketHandlerMapping$4(<generated>)
    at com.test.wsb.config.WebsocketConfig$$EnhancerBySpringCGLIB$$b414d315$$FastClassBySpringCGLIB$$f17bc7ca.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)
    at com.test.wsb.config.WebsocketConfig$$EnhancerBySpringCGLIB$$b414d315.stompWebSocketHandlerMapping(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
Cheetah
  • 13,785
  • 31
  • 106
  • 190
  • Why? Simply removing the jackson library from your classpath should be enough... The `MessageConverter`s etc. are autodetected based on the classes that are available. – M. Deinum Jul 04 '14 at 10:04
  • @M.Deinum - If I do that I get a class not found exception? `Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.JsonMappingException` – Cheetah Jul 04 '14 at 10:26
  • Then you have something in your code/config that depends on it or you haven't removed/excluded all the dependencies. – M. Deinum Jul 04 '14 at 10:33
  • @M.Deinum - is there something I should be excluding the in the POM from the spring libraries?...I'm 100% sure my code (there is no xml) doesn't reference Jackson and its not explicitly on my classpath/in my pom. – Cheetah Jul 04 '14 at 10:37
  • Jackson libaries are optional (at least for the spring libaries). You probably want to do a `mvn dependency:tree` to see what is pulling in what and figure out where to exclude the jackson library. – M. Deinum Jul 04 '14 at 10:39
  • @M.Deinum - I've had a look and its definitely a Spring dependency that is causing the issue. I believe `AbstractHttpReceivingTransportHandler` is the offending class. – Cheetah Jul 04 '14 at 10:50
  • Use `mvn dependency:tree` to see which library i pulling in the jackson libraries. In spring the only mandatory dependency is commons-logging all the other are optional. The fact that a class uses jackson doesn't mean it gets instantiated. – M. Deinum Jul 04 '14 at 10:53
  • @M.Deinum - Sorry, I should have mentioned...I did that. Jackson is not in the dependency tree. The `DefaultSockJsService` class uses a `XhrReceivingTransportHandler` which is a `AbstractHttpReceivingTransportHandler`. I've added a stack-trace. – Cheetah Jul 04 '14 at 10:58
  • Of course the dependency is not in there or you wouldn't get a classnotfound ;) I can only guess but judging by the stacktrace the real problem here is that there is no actual alternative on the classpath; Spring seems to want to configure a default transport handler and the default is apparently the non-existing Jackson. – Gimby Jul 04 '14 at 11:07
  • Instead of the default you can configure the `TransportHandlingSockJsService` by explictly specifing which `handlers` yuo want to use. However I would consider it a work-around. All the mvc code is doing detection for jackson and here is a class which assumes that it is on the classpath. I suggest you register a bug/enhancement for spring-websockets in [jira](http://jira.spring.io). – M. Deinum Jul 04 '14 at 11:11
  • Thanks Marten for suggesting a JIRA issue! – Brian Clozel Jul 07 '14 at 15:39

1 Answers1

0

SPR-11963 has been created following this question, and is now resolved.

This has landed in Spring Framework 4.0.6.

Brian Clozel
  • 56,583
  • 15
  • 167
  • 176