【发布时间】:2015-09-16 12:18:01
【问题描述】:
我是 neo4j 和 jersey 的新手。我正在尝试按照 neo4j 文档使用 Java 中的 Cypher 端点和 Jersey 从服务器 [1]、[2] 进行简单查询。我的代码低于[4]。以及我的 pom.xml [5]。
我一直遇到一个错误,我在板上看到了很多关于缺少消息正文编写器的错误 [6]。一些解决方案涉及编辑其余服务器代码和添加注释。我正在寻找不同的解决方案,因为我计划使用 neo4j 服务器作为开箱即用的图形数据库。我已经包含了我的 pom,因为许多其他答案都建议包括解决问题的特定软件包。我尝试将这些包括在内,并看到了如此成功。
有什么想法吗?
[1]http://neo4j.com/docs/2.2.3/cypher-intro-applications.html
[2]http://neo4j.com/docs/stable/server-java-rest-client-example.html#_creating_a_node
[4] 字符串查询 = "MATCH (m:Movie) RETURN m";
String uri = host + "/db/data/transaction/commit";
String cypherStatements = "{\"statements\": [\"statement\":{"+query+"}]}";
WebResource resource = Client.create().resource((uri));
ClientResponse response = resource.accept(MediaType.APPLICATION_JSON)
.type(MediaType.APPLICATION_JSON)
.entity(cypherStatements)
.post(ClientResponse.class);
System.out.println(String
.format("PUT to [%s], status code [%d]", uri, response.getStatus()));
[5]
http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0
<build>
<plugins>
<plugin>
<!-- Assemble the jar file including all it's dependencies. This is nescesary
for DataCleaner to load them all collectively. -->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<!--<repository>-->
<!--<id>snapshot-repository.java.net</id>-->
<!--<name>Java.net Snapshot Repository for Maven</name>-->
<!--<url>https://maven.java.net/content/repositories/snapshots/</url>-->
<!--<layout>default</layout>-->
<!--</repository>-->
<repository>
<id>maven-repository.java.net</id>
<name>Java.net Maven 1 Repository</name>
<url>http://download.java.net/maven/2</url>
<layout>legacy</layout>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.owlike</groupId>
<artifactId>genson</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<!-- Include DataCleaner as a provided dependency -->
<groupId>org.eobjects.datacleaner</groupId>
<artifactId>DataCleaner-desktop-ui</artifactId>
<version>4.0-RC3</version>
<scope>provided</scope>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
[6]
java.util.concurrent.ExecutionException: com.sun.jersey.api.client.ClientHandlerException: com.sun.jersey.api.client.ClientHandlerException: Java 类型的消息体编写器,类 java.lang.String,并且未找到 MIME 媒体类型 application/json
com.sun.jersey.api.client.ClientHandlerException:com.sun.jersey.api.client.ClientHandlerException:Java 类型、java.lang.String 类和 MIME 媒体类型 application/json 的消息正文编写器, 没找到
com.sun.jersey.api.client.ClientHandlerException:找不到 Java 类型、java.lang.String 类和 MIME 媒体类型 application/json 的消息正文编写器
找不到 Java 类型 java.lang.String 类和 MIME 媒体类型 application/json 的消息正文编写器
【问题讨论】: