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>

猜你喜欢

转载自blog.csdn.net/mbshqqb/article/details/79551860