使用Spring和Jackson API的BeanCreationException

时间:2012-06-10 13:15:19

标签: spring jackson

我试图在Spring 3.0.6中使用Jackson API时遇到异常。我有v1.8.9的jackson jars(core-asl,mapper-asl)进入类路径但仍然由于一些冲突的jar我面临错误::

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

2 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:0)

感谢您的回复。但是,我可以解决一些R&amp; D的问题...我不需要转到Jackson v1.4.2,而是在JBoss配置本身稍作修改时使用了相同的版本。

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

这里JBoss使用自己的Jackson API版本(虽然我们在classpath中有不同的版本)。所以我复制了v1.8.9并在module.xml中进行了相应的更改(在同一目录中)。对于mapper jar v1.8.9,重复了类似的事情。

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