Could not load driver class org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'neo4jAuditionBeanFactoryPostProcessor': Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/zj/dataserver/ApplicationConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.neo4j.ogm.session.SessionFactory]: Factory method 'sessionFactory' threw exception; nested exception is org.neo4j.ogm.exception.core.ConfigurationException: Could not load driver class org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver

遇到这个问题主要SessionFactory创建失败

先看一下代码,然后说明需要注意的地方:

@Configuration
@EnableAutoConfiguration
@EnableNeo4jRepositories("com.zj.dataserver.repository")
@EnableTransactionManagement
public class ApplicationConfiguration{
    @Bean
    public SessionFactory sessionFactory() {
        return new SessionFactory(configuration(),"com.zj.dataserver.domain");
    }
    @Bean
    public org.neo4j.ogm.config.Configuration configuration() {
        ConfigurationSource properties = new ClasspathConfigurationSource("db.properties");
        org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration.Builder(properties).build();
        System.out.println(configuration.getURI());
        return configuration;
    }
    @Bean
    public Neo4jTransactionManager transactionManager() throws Exception {
        return new Neo4jTransactionManager(sessionFactory());
    }
}  

报相同的错误,原因找不到db.properties或db.properties中的配置有误

解决办法:

1. 配置

错误配置(不知道是从哪儿找来的)

#Neo4j配置
spring.data.neo4j.username=neo4j
spring.data.neo4j.password=mbshqqb
#数据库uri地址
spring.data.neo4j.uri=bolt://localhost:7474

官网配置:

URI=http://localhost:7474
username=neo4j
password=mbshqqb

2. 直接通过代码写死

 @Bean
    public org.neo4j.ogm.config.Configuration configuration() {
        org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration.Builder()
                .uri("http://localhost:7474")
                .credentials("neo4j", "mbshqqb")
                .build();
        return configuration;
    }
若继续报错,可尝试下面的几处修改:

1. 默认为bolt,只有从配置文件修改后会变成http

new SessionFactory(configuration(),"com.zj.dataserver.domain");

2. 默认为bolt,即下面的‘http’为'bolt'

spring.data.neo4j.uri=http://localhost:7474

3. 添加httpdriver的依赖

<dependency>
	<groupId>org.neo4j</groupId>
	<artifactId>neo4j-ogm-http-driver</artifactId>
</dependency>
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值