我遇到了最新版本的Camel和REST DSL路由的问题。可以在此处找到并运行完整代码:https://github.com/mikevoxcap/nvisia-catalog-camel-service。当我尝试运行路线时,我遇到了异常,原因如下:
Caused by: java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.introspect.AnnotatedMember.getType()Lcom/fasterxml/jackson/databind/JavaType;
....
at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:926)
at org.apache.camel.component.jackson.JacksonDataFormat.marshal(JacksonDataFormat.java:154)
at org.apache.camel.processor.MarshalProcessor.process(MarshalProcessor.java:69)
我的问题是,我应该针对哪个版本的杰克逊不再接收此例外。
我引入了以下依赖项:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<spring.boot.version>1.3.5.RELEASE</spring.boot.version>
<camel.version>2.17.1</camel.version>
<java.version>1.8</java.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring.boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-servlet</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-swagger-java</artifactId>
<version>${camel.version}</version>
</dependency>
<!-- Testing -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring</artifactId>
<version>${camel.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
在对我收到的异常进行一些搜索之后,有几个人在版本冲突时遇到了这个问题。我注意到camel-jackson库引入了jackson-module-jaxb-annotations 2.7.2,但剩下的jackson库是2.6.6。我尝试排除jackson-module-jaxb-annotations 2.7.2然后直接包含2.6.6,但仍然导致异常。
我的路线相对简单:
// Definition of the get catalog item endpoint
rest("/catalogItem").
// This is a GET method call for getting a catalog item by ID.
get("{id}").
// Description of what this method does
description("Retrieve a catalog item by ID").
// Define the output type that will be returned from this method
outType(CatalogItem.class)
// Define where the message is routed to as a URI. Here we use a
// Spring Bean and define the bean method to invoke. Note that Camel
// has converted the ID placeholder from the URL into a header
// entry.
.to("bean:catalogService?method=getCatalogItem(${header.id})");
我的对象被用作JSON类型也很简单:
public class CatalogItem {
private int id;
private double price;
private String catalogItemType;
private List<CatalogItemAttribute> attributes;
public class CatalogItemAttribute {
private String attributeName;
private String attributeValue;
答案 0 :(得分:4)
虽然我还没有找到任何来自Camel的官方消息,但是一旦Spring Boot 1.4发布,它将会自行解决,因为它将支持Jackson 2.7。与此同时,我更新了我的依赖项,如下所示。我将jackson-annotations,jackson-core和jackson-databind库的排除项添加到spring-boot-starter-web,spring-boot-starter-actuator,camel-jackson和camel-swagger-java依赖项中。然后我用2.7.2指定了三个jackson依赖项。
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<artifactId>jackson-annotations</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-core</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<exclusions>
<exclusion>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
<version>${camel.version}</version>
<exclusions>
<exclusion>
<artifactId>jackson-annotations</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-core</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-servlet</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-swagger-java</artifactId>
<version>${camel.version}</version>
<exclusions>
<exclusion>
<artifactId>jackson-annotations</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-core</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
<exclusion>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<artifactId>jackson-annotations</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<version>2.7.2</version>
</dependency>
<dependency>
<artifactId>jackson-core</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<version>2.7.2</version>
</dependency>
<dependency>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<version>2.7.2</version>
</dependency>
<!-- Testing -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring</artifactId>
<version>${camel.version}</version>
<scope>test</scope>
</dependency>
</dependencies>