Spring boot jackson自动配置连接错误wildfly

时间:2015-10-15 14:48:26

标签: jboss jackson spring-boot wildfly

A.war - >是一个简单的春季启动REST应用程序使用版本1.2.6.RELEASE(内部使用spring 4.1.7 RELEASE,jackson 2.4.6)

B.jar - >是一个wildfly9共享模块(存储在wildfly / modules中),它使用包含spring框架的maven阴影插件打包(没有弹簧启动意味着使用添加spring项目依赖关系的旧方法)和与上面相同版本的jackson类。 (它的阴影是因为非spring和非容器项目可以在它们的类路径中添加这个jar并使用它 - 它可以工作)

A.war有maven依赖scope <provided> on B.jar,jboss-deployment-structure.xml和<dependencies> <module name = "B"> </dependencies> A.war部署失败,出现以下错误。

注意:当我删除B.jar jboss依赖时,A.war完全正常部署。因此添加B.jar会导致此问题。如果我不在A.war中使用spring boot(意思是如果我直接使用简单的spring webmvc和上下文依赖关系)和B.jar jboss依赖,那么A.war也可以完美地部署

任何人都可以解释下面的错误说明了什么以及我如何调查更多?

至于我对wildlfy类加载的理解,A.war和B.jar应该加载到不同的模块类加载器中,是否A.war在错误中抱怨了B.jar的jackson类?

Caused by: java.lang.LinkageError: loader constraint violation: when resolving method
 "org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.modulesToInstall([Lcom/fasterxml/jackson/databind/Module;)Lorg/springframework/http/converter/json/Jackson2ObjectMapperBuilder;"
 the class loader (instance of org/jboss/modules/ModuleClassLoader) of the current class,
 org/springframework/boot/autoconfigure/jackson/JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration,
 and the class loader (instance of org/jboss/modules/ModuleClassLoader) for resolved class,
 org/springframework/http/converter/json/Jackson2ObjectMapperBuilder,
 have different Class objects for the type der used in the signature
 at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration.configureModules(JacksonAutoConfiguration.java:259)
 at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration.jacksonObjectMapperBuilder(JacksonAutoConfiguration.java:186)
 at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration$$EnhancerBySpringCGLIB$$b993caa0.CGLIB$jacksonObjectMapperBuilder$1()
 at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration$$EnhancerBySpringCGLIB$$b993caa0$$FastClassBySpringCGLIB$$5262bf2.invoke()
 at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
 at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:318)
 at org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration$JacksonObjectMapperBuilderConfiguration$$EnhancerBySpringCGLIB$$b993caa0.jacksonObjectMapperBuilder()
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
 at java.lang.reflect.Method.invoke(Method.java:606)
 at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ... 108 more

1 个答案:

答案 0 :(得分:1)

在研究了更多jboss类加载行为之后,B.jar中的jackson类与来自jboss restesay模块的相同jackson类相冲突。 所以在jboss-deployment-structure.xml中将它们排除在下面后,这个问题就解决了。

<exclusions>
     <module name="org.jboss.resteasy.resteasy-jackson-provider"/> 
     <module name="org.jboss.resteasy.resteasy-jackson2-provider"/> 
</exclusions>