Spring Data Neo4J数据库连接

我正尝试使用Spring Data连接到Neo4J数据库使用以下链接(http://projects.spring.io/spring-data-neo4j/#quick-start)。 但它似乎并不奏效。 它无法自行创建Repository Implementation。 这就是为什么我得到BeanCreationException。 这里我到目前为止尝试过。

  • PersistenceContext.java
  • @Configuration
    @EnableTransactionManagement
    @ComponentScan("com.ksh.neo4j")
    @EnableNeo4jRepositories("com.ksh.neo4j.repositories")
    public class PersistenceContext  {
    
      @Bean
      public org.neo4j.ogm.config.Configuration getConfiguration() 
      {
          org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration();
          configuration.driverConfiguration()
                       .setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver")
                       .setURI("http://localhost:7474");
          return configuration;
      }
      @Bean
      public Neo4jTransactionManager transactionManager() {
          return new Neo4jTransactionManager(getSessionFactory());
      }
      @Bean
      public SessionFactory getSessionFactory() {
          return new SessionFactory("com.ksh.neo4j.domains");
      }
    }
    
  • PersonRepository.java
  • @Repository
    public interface PersonRepository extends GraphRepository<Person> {
    }
    
  • PersonService.java
  • @Service
    public class PersonService {  
      @Autowired
      private PersonRepository personRepository;
    
      public Person save(Person person) {
          return personRepository.save(person);
      }
    }
    
  • PersonController.java
  • @RestController
    @RequestMapping("/person/**")
    public class PersonController {
      @Autowired
      private PersonService personService;
    
      @RequestMapping("/save")
      public ResponseObject save(@RequestBody Person person) 
      {
          try {
              personService.save(person);
              return ResponseObjectCreator.createResponseObj(ResponseStatus.SUCSESS);
          }
          catch (Exception e) {
              e.printStackTrace();
          }
          return ResponseObjectCreator.createResponseObj(ResponseStatus.FAILURE); 
      }
    }
    
  • WebMvcConfig.java
  •  @Configuration
        @EnableWebMvc
        @ComponentScan(basePackages = {"com.ksh.neo4j.controllers", "com.ksh.neo4j"})
        public class WebMvcConfig extends WebMvcConfigurerAdapter {]
          @Override
          public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
              configurer.enable();
          }
        }
    
  • 的pom.xml
  • <dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-commons</artifactId>
      <version>1.13.1.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-neo4j</artifactId>
      <version>4.2.1.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>4.3.7.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>4.3.7.RELEASE</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.neo4j</groupId>
      <artifactId>neo4j-ogm-embedded-driver</artifactId>
      <version>2.1.2</version>
    </dependency>
    <dependency>
      <groupId>org.neo4j</groupId>
      <artifactId>neo4j-ogm-core</artifactId>
      <version>2.1.1</version>
    </dependency>
    <dependency>
      <groupId>org.neo4j</groupId>
      <artifactId>neo4j-ogm-http-driver</artifactId>
      <version>2.1.1</version>
    </dependency>
    <dependency>
      <groupId>org.neo4j</groupId>
      <artifactId>neo4j-kernel</artifactId>
      <version>3.1.3</version>
    </dependency>
    <dependency>
      <groupId>org.neo4j.app</groupId>
      <artifactId>neo4j-server</artifactId>
      <version>3.1.3</version>
    </dependency>
    

    我得到以下异常

    引起:org.springframework.beans.BeanInstantiationException:无法实例化[org.neo4j.ogm.session.SessionFactory]:工厂方法'getSessionFactory'抛出异常; 嵌套的异常是org.neo4j.ogm.exception.ServiceNotFoundException:无法加载驱动程序:null。

    任何帮助都会很好。


    你没有说你正在使用哪个版本,但是如果你使用4.2.1,那么快速启动似乎缺少事务管理器定义:

    将以下内容添加到您的PersistenceContext类中:

    @Bean
    public Neo4jTransactionManager transactionManager() {
        return new Neo4jTransactionManager(sessionFactory());
    }
    

    有关更多详细信息,请参阅spring-data-neo4j文档。

    http://docs.spring.io/spring-data/data-neo4j/docs/current/reference/html/#reference.getting_started.spring-configuration

    链接地址: http://www.djcxy.com/p/68775.html

    上一篇: Spring Data Neo4J Database Connection

    下一篇: I am creating an shopping cart and i get some error