我是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:电影)返回m&#34 ;;
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
答案 0 :(得分:0)
哦,看起来你正在使用客户端,但没有正确定义端点?在这种情况下,您需要向客户端注册消息正文编写器/阅读器,自动发现仅适用于服务器端。
使用Genson,你可以this way。