我使用jackson转换器(MappingJacksonHttpMessageConverter)来消耗并从spring控制器生成json数据。但是在调用控制器时抛出异常。
Caused by: java.lang.NoSuchMethodError: org.codehaus.jackson.type.JavaType.isConcrete()Z
at org.codehaus.jackson.map.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:80)
at org.codehaus.jackson.map.deser.StdDeserializerProvider._createDeserializer(StdDeserializerProvider.java:266)
at org.codehaus.jackson.map.deser.StdDeserializerProvider._createAndCacheValueDeserializer(StdDeserializerProvider.java:198)
at org.codehaus.jackson.map.deser.StdDeserializerProvider.hasValueDeserializerFor(StdDeserializerProvider.java:152)
at org.codehaus.jackson.map.ObjectMapper.canDeserialize(ObjectMapper.java:829)
我的代码:
Spring bean文件:
abc.CartType abc.CartResponseType
pom文件(仅限片段)
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<compileSource>1.5</compileSource>
<org.springframework.version>3.0.2.RELEASE</org.springframework.version>
<jboss.server.name>network-epro</jboss.server.name>
</properties>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-api</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>2.1.4</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2</version>
</dependency>
<dependency>
<groupId>sso</groupId>
<artifactId>casclient</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.1.5.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib-ext-spring</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>xpp</groupId>
<artifactId>xpp</artifactId>
<version>2.3.0</version>
</dependency>
<!-- http://code.google.com/p/jsonp-java/ -->
<dependency>
<groupId>org.jsonp</groupId>
<artifactId>jsonp</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>email</groupId>
<artifactId>email-client</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.2.2.ga</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<!--
Jboss client dependancy.
-->
<dependency>
<groupId>jboss</groupId>
<artifactId>jbossall-client</artifactId>
<version>4.2.2.GA</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-oxm-tiger</artifactId>
<version>1.5.9</version>
</dependency>
我可以在spring-web pom文件中看到jackson版本被提到1.4.2和我使用的相同仍然是关于未找到的方法抛出异常。我使用的是正确的版本吗?
答案 0 :(得分:1)
您似乎错过了jackson-core
依赖项。您需要jackson-mapper
。
1.4.x版本应该没问题,但将它升级到更新的版本应该没什么坏处。
答案 1 :(得分:1)
我认为你在Jackson核心和映射器jar之间有不同的版本(以前有流解析器/生成器;后面的数据绑定)。很难确保传递依赖项具有兼容版本 - 虽然多个Jackson版本在Spring(以及大多数其他框架)中运行得很好,但mapper和core的版本具有更严格的依赖性。
具体来说:核心版本不应该比mapper版本更旧,因为较新的映射器版本依赖于核心中的新功能。反向较少;因此,使用较旧的映射器版本,较新的核心(此时核心也会以更慢的速度改变)通常很好。
答案 2 :(得分:1)
我发现了问题。
使用Jacson版本1.4.2应该没有问题,因为StaxMan建议核心可靠地用于映射器,因此它将自动解决,无需明确声明它。
现在回到问题。它是jboss中的类路径问题。我有两个Web应用程序部署在同一个服务器上,依赖于jacson versioin 1.1.1和其他一个1.4.2。我还没有解决方案,所以我发布了另一个与Jboss相关的question。