【发布时间】:2014-07-04 10:01:55
【问题描述】:
在 Spring-MVC 中,您可以将 Jackson 库作为依赖项删除,并使用以下方法将其替换为您自己的:
protected void configureMessageConverters(List<HttpMessageConverter<?>> converters)
我正在尝试对 Spring-Websocket 做同样的事情,所以我已经覆盖了这两种方法:
@Bean public CompositeMessageConverter brokerMessageConverter()
protected boolean configureMessageConverters(List<MessageConverter> messageConverters)
但是在某个地方仍然依赖于杰克逊,我不知道在哪里。
编辑
这是一个堆栈跟踪:
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)
【问题讨论】:
-
为什么?只需从类路径中删除 jackson 库就足够了...
MessageConverters 等会根据可用的类自动检测。 -
@M.Deinum - 如果我这样做,我会得到一个找不到类的异常?
Caused by: java.lang.ClassNotFoundException: com.fasterxml.jackson.databind.JsonMappingException -
那么你的代码/配置中有一些依赖它的东西,或者你没有删除/排除所有依赖项。
-
@M.Deinum - 我应该从 Spring 库中排除 POM 中的内容吗?...我 100% 确定我的代码(没有 xml)没有引用杰克逊和它没有明确地在我的类路径/在我的 pom 中。
-
Jackson 库是可选的(至少对于 spring 库)。你可能想做一个
mvn dependency:tree来看看是什么在拉什么,并找出排除杰克逊库的位置。
标签: java spring spring-websocket