我的neo4j版本为3.3.2 相关算法需要apoc的函数,我成功引入apoc在浏览器命令行里可以成功执行遍历,语句为:
MATCH (c:Character) WITH collect© AS characters CALL apoc.algo.betweenness([‘INTERACTS’], characters, ‘BOTH’) YIELD node, score SET node.betweenness = score RETURN node.name AS name, score ORDER BY score DESC
现在java代码中嵌入式访问数据库利用GraphDatabaseService的execute方法执行上述语句,会报错: there is no procedure with the name ‘apoc.algo.betweenness’ registered for this database instance. 各位大神这该如何解决?
execute 没问题啊,如下,可以正常运行:
package com.app.components;
@Component
public class Neo4jWarmup {
private static final Logger LOG = LogManager.getLogger(StartupTasks.class);
@Autowired
GraphDatabaseService db;
/*
* this did the trick - the method gets called
* after Spring initialization and the DB works as expected
*/
@Autowired
public void neo4jWarmup() {
executeTestSelect();
}
private void executeTestSelect() {
LOG.info("Warming up Neo4j...");
Transaction tx = db.beginTx();
db.execute("CALL apoc.warmup.run()");
tx.close();
LOG.info("Warmup complete.");
}
}
@pangguoming 我去执行你这个存储过程也报这类错误 是不是获取neo4j数据库实例的时候要读取相关配置的?我直接启动没有像网上说的 new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(new File("##")).oadPropertiesFromFile("##").newGraphDatabase()这样,直接newEmbeddedDatabase()没读配置
嵌入模式下需要在代码中注册APOC过程。可以参考这个例子: https://github.com/neo4j-contrib/rabbithole/blob/3.0/src/main/java/org/neo4j/community/console/Neo4jService.java#L55