1

在尝试将 Jackson API 与 Spring 3.0.6 一起使用时,我遇到了以下异常。我在类路径中有 v1.8.9(core-asl,mapper-asl)的杰克逊罐子,但仍然由于一些冲突的罐子我面临错误::

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#8': Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.codehaus.jackson.type.JavaType.<init>(Ljava/lang/Class;I)V
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:965) [org.springframework.beans-3.0.6.RELEASE.jar:]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911) [org.springframework.beans-3.0.6.RELEASE.jar:]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485) [org.springframework.beans-3.0.6.RELEASE.jar:]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [org.springframework.beans-3.0.6.RELEASE.jar:]
    at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveInnerBean(BeanDefinitionValueResolver.java:270) [org.springframework.beans-3.0.6.RELEASE.jar:]
    ... 30 more
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.http.converter.json.MappingJacksonHttpMessageConverter]: Constructor threw exception; nested exception is java.lang.NoSuchMethodError: org.codehaus.jackson.type.JavaType.<init>(Ljava/lang/Class;I)V
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:141) [org.springframework.beans-3.0.6.RELEASE.jar:]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:74) [org.springframework.beans-3.0.6.RELEASE.jar:]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:958) [org.springframework.beans-3.0.6.RELEASE.jar:]
    ... 34 more
Caused by: java.lang.NoSuchMethodError: org.codehaus.jackson.type.JavaType.<init>(Ljava/lang/Class;I)V
    at org.codehaus.jackson.map.type.TypeBase.<init>(TypeBase.java:13) [jackson-mapper-asl-1.8.9.jar:]
    at org.codehaus.jackson.map.type.SimpleType.<init>(SimpleType.java:39) [jackson-mapper-asl-1.8.9.jar:]
    at org.codehaus.jackson.map.type.SimpleType.constructUnsafe(SimpleType.java:56) [jackson-mapper-asl-1.8.9.jar:]
    at org.codehaus.jackson.map.ObjectMapper.<clinit>(ObjectMapper.java:188) [jackson-mapper-asl-1.8.9.jar:]
    at org.springframework.http.converter.json.MappingJacksonHttpMessageConverter.<init>(MappingJacksonHttpMessageConverter.java:56) [org.springframework.web-3.0.6.RELEASE.jar:]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [:1.6.0_24]
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) [:1.6.0_24]
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [:1.6.0_24]
    at java.lang.reflect.Constructor.newInstance(Constructor.java:532) [:1.6.0_24]
    at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:126) [org.springframework.beans-3.0.6.RELEASE.jar:]
    ... 36 more
4

2 回答 2

3

Jackson 对 Spring 3.0.6 的正确版本依赖是 1.4.2(每个 Spring 的 pom),尝试用这个版本替换 1.8.9,它应该可以正常工作。

于 2012-06-10T13:29:35.653 回答
0

感谢您的回复。但是,我可以通过一些研发来解决这个问题……我不需要去 Jackson v1.4.2,而是使用相同的版本,并在 JBoss 配置本身中稍作修改。

在 JBoss 中,转到 modules/org/codehaus/jackson/jackson-core-asl/main/

这里 JBoss 使用它自己的 Jackson API 版本(尽管我们在类路径中有不同的版本)。所以我复制了 v1.8.9 并在 module.xml 中进行了相应的更改(在同一目录中)。mapper jars v1.8.9 重复了类似的事情。

有了这个,我可以解决问题并再次运行...... :)

于 2012-06-11T06:56:56.403 回答