私はいくつかのユニットテストを書いており、Springリポジトリと共にTimeTreeを使い、イベントノードを時間木に自動接続します。 thisのようなものですが、私はboot 2.0とSDN5を使用しています。私の主な問題は、私のリポジトリと私のTimeTreeが同じGraphDatabaseServiceを使用するように設定を設定する方法がわからないことだと思います。私@Confurationは、このようなものです:Boot2.0とNeo4j SDN5のSpring Unitテストで独自のGraphDatabaseServiceとGraphAwareRuntimeを設定するには
@Configuration
public class SpringConfig {
@Bean
public SessionFactory sessionFactory() {
// with domain entity base package(s)
return new SessionFactory(configuration(), "org.neo4j.boot.test.domain");
}
@Bean
public org.neo4j.ogm.config.Configuration configuration() {
return new org.neo4j.ogm.config.Configuration.Builder()
.uri("bolt://localhost")
.build();
}
@Bean
public Session getSession() {
return sessionFactory().openSession();
}
@Bean
public GraphDatabaseService graphDatabaseService() {
return new GraphDatabaseFactory()
.newEmbeddedDatabase(new File("/tmp/graphDb"));
}
@Bean
public GraphAwareRuntime graphAwareRuntime() {
GraphDatabaseService graphDatabaseService = graphDatabaseService();
GraphAwareRuntime runtime = GraphAwareRuntimeFactory
.createRuntime(graphDatabaseService);
runtime.registerModule(new TimeTreeModule("timetree",
TimeTreeConfiguration
.defaultConfiguration()
.withAutoAttach(true)
.with(new NodeInclusionPolicy() {
@Override
public Iterable<Node> getAll(GraphDatabaseService graphDatabaseService) {
return null;
}
@Override
public boolean include(Node node) {
return node.hasLabel(Label.label("User"));
}
})
.withRelationshipType(RelationshipType.withName("CREATED_ON"))
.withTimeZone(DateTimeZone.forTimeZone(TimeZone.getTimeZone("GMT+1")))
.withTimestampProperty("createdOn")
.withResolution(Resolution.DAY)
// .withCustomTimeTreeRootProperty("timeTreeName")
.withResolution(Resolution.HOUR), graphDatabaseService));
runtime.start();
return runtime;
}
}
そして、私のテストは次のようになります。
User user = new User("Michal");
user.setCreatedOn(1431937636995l);
userRepository.save(user);
GraphUnit.assertSameGraph(graphDb, "CREATE (u:User {name:'Michal', createdOn:1431937636995})," +
"(root:TimeTreeRoot)," +
"(root)-[:FIRST]->(year:Year {value:2015})," +
"(root)-[:CHILD]->(year)," +
"(root)-[:LAST]->(year)," +
"(year)-[:FIRST]->(month:Month {value:5})," +
"(year)-[:CHILD]->(month)," +
"(year)-[:LAST]->(month)," +
"(month)-[:FIRST]->(day:Day {value:18})," +
"(month)-[:CHILD]->(day)," +
"(month)-[:LAST]->(day)," +
"(day)<-[:CREATED_ON]-(u)"
);
GraphUnit.printGraph(graphDb);
graphDb.shutdown();
あり、エラーのホストだが、私は彼らのすべてがこの1由来だと思う:
Bean instantiation via factory method failed; nested exception is
org.springframework.beans.BeanInstantiationException: Failed to
instantiate [org.springframework.data.repository.support.Repositories]:
Factory method 'repositories' threw exception; nested exception is
org.springframework.beans.factory.UnsatisfiedDependencyException: Error
creating bean with name 'userRepository': Unsatisfied dependency
expressed through method 'setSession' parameter 0; nested exception is
org.springframework.beans.factory.NoUniqueBeanDefinitionException: No
qualifying bean of type 'org.neo4j.ogm.session.Session' available:
expected single matching bean but found 2: getSession,
org.springframework.data.neo4j.transaction.SharedSessionCreator#0
多くのおかげで、見えます。私たちが会うことが起これば私の上のビール! –