我正在尝试构建一个扩展以在 neo4j 中动态插入一些数据,但无济于事。
这是我的扩展代码:
@Path("/inserter")
public class Inserter {
private final GraphDatabaseService db;
public Inserter(@Context GraphDatabaseService db){
this.db = db;
}
@POST
@Consumes(MediaType.APPLICATION_JSON)
@Path("/insert")
public void insert(Person x){
Transaction tr = db.beginTx();
//Do something
tr.success();
tr.finish();
}
}
这是我的 Person 对象:
package org.neo4j.server.plugin.plugin.messages;
public class Person {
public String name;
public int id;
public String email;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
我尝试了很多不同的方法,但到目前为止都没有奏效。使用上面的代码得到一个 415 错误,说“不支持的媒体类型”
我试图将杰克逊 json 提供程序添加到我的项目中。它改变了我的错误,但我不知道如何处理这个问题。现在的错误是:
错误 500 com.fasterxml.jackson.databind.ObjectWriter.getFactory()Lcom/fasterxml/jackson/core/JsonFactory;
java.lang.NoSuchMethodError: com.fasterxml.jackson.databind.ObjectWriter.getFactory()Lcom/fasterxml/jackson/core/JsonFactory;
为了测试我的扩展,我使用了 Google REST 控制台,将 RequestUri 设置为 localhost:7474/myextensions/inserter/insert,Content-Type 设置为 application/json,请求正文如下:
{"id":100,"name":"Bibi","email":"yopmail"}
编辑:这是maven依赖树(不确定它是否与给我带来麻烦的完全相同,因为自从我提出问题以来我更改了很多代码)
[INFO] org.neo4j.server.plugin:neo4j-antvoice-plugin:jar:0.0.1-SNAPSHOT
[INFO] +- org.apache.cxf:cxf-rt-frontend-jaxws:jar:2.7.5:compile
[INFO] | +- xml-resolver:xml-resolver:jar:1.2:compile
[INFO] | +- asm:asm:jar:3.3.1:compile
[INFO] | +- org.apache.cxf:cxf-api:jar:2.7.5:compile
[INFO] | | +- org.codehaus.woodstox:woodstox-core-asl:jar:4.2.0:compile
[INFO] | | | \- org.codehaus.woodstox:stax2-api:jar:3.1.1:compile
[INFO] | | +- org.apache.ws.xmlschema:xmlschema-core:jar:2.0.3:compile
[INFO] | | +- org.apache.geronimo.specs:geronimo-javamail_1.4_spec:jar:1.7.1:compile
[INFO] | | \- wsdl4j:wsdl4j:jar:1.6.3:compile
[INFO] | +- org.apache.cxf:cxf-rt-core:jar:2.7.5:compile
[INFO] | | \- com.sun.xml.bind:jaxb-impl:jar:2.2.6:compile
[INFO] | +- org.apache.cxf:cxf-rt-bindings-soap:jar:2.7.5:compile
[INFO] | | \- org.apache.cxf:cxf-rt-databinding-jaxb:jar:2.7.5:compile
[INFO] | +- org.apache.cxf:cxf-rt-bindings-xml:jar:2.7.5:compile
[INFO] | +- org.apache.cxf:cxf-rt-frontend-simple:jar:2.7.5:compile
[INFO] | \- org.apache.cxf:cxf-rt-ws-addr:jar:2.7.5:compile
[INFO] | \- org.apache.cxf:cxf-rt-ws-policy:jar:2.7.5:compile
[INFO] | \- org.apache.neethi:neethi:jar:3.0.2:compile
[INFO] +- org.apache.cxf:cxf-rt-transports-http:jar:2.7.5:compile
[INFO] +- org.neo4j:neo4j:jar:2.0.0-M03:compile
[INFO] | +- org.neo4j:neo4j-kernel:jar:2.0.0-M03:compile
[INFO] | | \- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
[INFO] | +- org.neo4j:neo4j-lucene-index:jar:2.0.0-M03:compile
[INFO] | | \- org.apache.lucene:lucene-core:jar:3.6.2:compile
[INFO] | +- org.neo4j:neo4j-graph-algo:jar:2.0.0-M03:compile
[INFO] | +- org.neo4j:neo4j-udc:jar:2.0.0-M03:compile
[INFO] | +- org.neo4j:neo4j-graph-matching:jar:2.0.0-M03:compile
[INFO] | +- org.neo4j:neo4j-cypher:jar:2.0.0-M03:compile
[INFO] | | +- org.scala-lang:scala-library:jar:2.10.0:compile
[INFO] | | \- com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-lru:jar:1.3.1:compile
[INFO] | \- org.neo4j:neo4j-jmx:jar:2.0.0-M03:compile
[INFO] +- org.neo4j:server-api:jar:2.0.0-M03:compile
[INFO] | +- org.neo4j.3rdparty.javax.ws.rs:jsr311-api:jar:1.1.2.r612:compile
[INFO] | +- commons-configuration:commons-configuration:jar:1.6:compile
[INFO] | | +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] | | +- commons-lang:commons-lang:jar:2.4:compile
[INFO] | | +- commons-logging:commons-logging:jar:1.1.1:compile
[INFO] | | \- commons-beanutils:commons-beanutils-core:jar:1.8.0:compile
[INFO] | \- commons-digester:commons-digester:jar:1.8.1:compile
[INFO] | \- commons-beanutils:commons-beanutils:jar:1.8.0:compile
[INFO] +- com.google.protobuf:protobuf-java:jar:2.5.0:compile
[INFO] \- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.2.1:compile
[INFO] +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.2.1:compile
[INFO] +- com.fasterxml.jackson.core:jackson-core:jar:2.2.1:compile
[INFO] +- com.fasterxml.jackson.core:jackson-databind:jar:2.2.1:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-annotations:jar:2.2.1:compile
[INFO] \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.2.1:compile