报错信息:
Caused by: org.neo4j.kernel.StoreLockException: Store and its lock file has been locked by another process: D:\neo4j-com
产生异常的原因是,以内嵌方式连接的话,一个库应该是只能有一个连接
而在cmd 中以下面的命令启动neo4j时
neo4j.bat console
neo4j 自己带的web应用就连上了默认的数据库,“data/databases/graph.db”。
所以我们要以 HTTP的形式连接
我这里用的是SpringData neo4j连接的,连接配置方下面
/**
* Spring JavaConfig configuration class to setup a Spring container and infrastructure components.
*/
@Configuration
@EnableNeo4jRepositories(basePackages = "org.jsg.dao") // 我们操作数据的包名
@EnableTransactionManagement
public class GraphDBConfiguration extends Neo4jConfiguration {
@Bean
public org.neo4j.ogm.config.Configuration getConfiguration() {
org.neo4j.ogm.config.Configuration config =
new org.neo4j.ogm.config.Configuration();
/** 以内嵌的方式连接 **/
/* config.driverConfiguration()
.setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver") // 驱动名
.setURI("file:/D:/neo4j-community-3.4.5/data/databases/graph.db"); // 要连接数据库所在位置*/
/** 以HTTP的方式连接 **/
config.driverConfiguration()
.setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver") // 驱动名
.setURI("http://neo4j:admin@localhost:7474"); // 以【http://用户名:密码@域名:端口】的形式
return config;
}
@Override
@Bean
public SessionFactory getSessionFactory() {
return new SessionFactory(getConfiguration(), "org.jsg.domain"); // 基础实体存在的包位置
}
}
刚开始我用内嵌的方式死活连不了默认库,后来换HTTP的方式就行了