编辑:现在的问题是,即使调用了start,{}仅激活了版本2.0.0-M03的空数据库(在1.9.2中永远不会被调用),并且在那里有数据.createdNodes()返回一个空迭代器,即使创建了一个节点。因此,注册事务处理程序似乎仍有问题。我将此标记为已解决,因为问题与PluginLifecycle没有任何关系。我发布了一个新问题https://github.com/ttiurani/neo4j-uuid/blob/master/src/main/java/org/neo4j/extension/uuid/UUIDTransactionEventHandler.java。
ORIGINAL:
我正在尝试让Neo4j在嵌入式服务器中使用自定义PluginLifecycle实现。出于某种原因,Neo4j调用实现的构造函数两次,但从不调用start()方法。自定义PluginLifecycle实现在这里:
这是一个测试项目:
的pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>example</groupId>
<artifactId>neo4j-embedded-pluginlifecycle-test</artifactId>
<packaging>jar</packaging>
<name>Neo4j Embedded PluginLifecycle Implementation Test</name>
<version>1.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<neo4j.version>2.0.0-M03</neo4j.version>
</properties>
<repositories>
<repository>
<id>neo4j-public-repository</id>
<url>http://m2.neo4j.org</url>
</repository>
<repository>
<id>oss-sonatype-snapshots</id>
<name>OSS Sonatype Snapshots</name>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>
</repositories>
<dependencies>
<!-- Neo4j graph database -->
<dependency>
<groupId>org.extendedmind</groupId>
<artifactId>neo4j-uuid</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>server-api</artifactId>
<version>${neo4j.version}</version>
</dependency>
<dependency>
<groupId>org.neo4j.app</groupId>
<artifactId>neo4j-server</artifactId>
<version>${neo4j.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.neo4j.app</groupId>
<artifactId>neo4j-server</artifactId>
<classifier>static-web</classifier>
<version>${neo4j.version}</version>
</dependency>
<!-- JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<addMavenDescriptor>false</addMavenDescriptor>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
的src /测试/ JAVA /示例/ PluginLifecycleTest.java:
package example;
import org.junit.Test;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.Transaction;
import org.neo4j.graphdb.factory.GraphDatabaseFactory;
import org.neo4j.kernel.GraphDatabaseAPI;
import org.neo4j.server.WrappingNeoServerBootstrapper;
import org.neo4j.server.configuration.Configurator;
import org.neo4j.server.configuration.ServerConfigurator;
public class PluginLifecycleTest{
@Test
public void shouldCreateUUIDToNewNode()
{
GraphDatabaseAPI graphdb = (GraphDatabaseAPI) new GraphDatabaseFactory()
.newEmbeddedDatabaseBuilder( "/tmp/neo4j-test" )
.newGraphDatabase();
new UUIDPluginLifecycle().start(graphdb, null);
ServerConfigurator config;
config = new ServerConfigurator( graphdb );
config.configuration().setProperty(
Configurator.THIRD_PARTY_PACKAGES_KEY, "org.neo4j.extension.uuid=/uuid");
config.configuration().setProperty(
Configurator.WEBSERVER_PORT_PROPERTY_KEY, 7473);
WrappingNeoServerBootstrapper srv = new WrappingNeoServerBootstrapper( graphdb, config );
srv.start();
Transaction tx = graphdb.beginTx();
Node node = graphdb.createNode();
node.setProperty("test", "test");
long id = node.getId();
tx.success();
tx = graphdb.beginTx();
node = graphdb.getNodeById(id);
node.getProperty("test");
// New nodes should have a "uuid" property
node.getProperty("uuid");
tx.success();
srv.stop();
}
}
由于某种原因,这不适用于错误“org.neo4j.graphdb.NotFoundException:org.neo4j.kernel.api.exceptions.PropertyKeyNotFoundException:未找到属性键'uuid'”。我尝试过使用1.9.2,但问题仍然存在。
我还需要做些什么才能让它发挥作用吗?
答案 0 :(得分:1)
尝试在嵌入模式下使用neo4j-uuid时,不需要服务器组件。最简单的方法是打电话:
GraphDatabaseService graphdb = new GraphDatabaseFactory()
.newEmbeddedDatabaseBuilder( "/tmp/neo4j-test" )
.newGraphDatabase();
new UUIDPluginLifecycle().start(graphDb, null);
并且UUID插件应该可以工作。
如果您还需要服务器组件,例如你想允许远程访问,我必须做更多的调试。我的猜测是,非托管扩展需要打包在一个jar文件中。