Spring-使用 Spring-Data-Neo4j 教程问题启动

Spring-Boot with Spring-Data-Neo4j Tutorial Problems

我正在尝试使用 spring-boot 和 spring-data-neo4j 开始一个项目,所以我正在学习这些教程:

https://neo4j.com/developer/spring-data-neo4j/

https://projects.spring.io/spring-data-neo4j/

但快速入门对我不起作用,我收到此错误: method does not override or implement a method from a supertype 对于这段代码(@override 部分):

import org.neo4j.ogm.session.SessionFactory;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.neo4j.ogm.MetaData;
//import org.neo4j.ogm.config.Configuration;

/**
* Defines the how the application persists data.
* Application uses Spring Data Neo4j, which wraps
* around the Neo4j OGM to communicate with the Neo4j
* database
*/
@Configuration
@EnableNeo4jRepositories("org.neo4j.cineasts.repository")
@EnableTransactionManagement
@ComponentScan("org.neo4j.cineasts")
public class PersistenceContext {

 /**
  * Starts a session with the database.
  */
 @Override
 public SessionFactory getSessionFactory() {
   return new SessionFactory("org.neo4j.cineasts.domain");
 }
}

我试着按照这里的方法签名: https://github.com/neo4j/neo4j-ogm/blob/v2.1.5/core/src/main/java/org/neo4j/ogm/session/SessionFactory.java#L61-L109

这是我的 pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>mygroup</groupId>
  <artifactId>myapp</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>myapp</name>
  <description>myapp's description</description>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.9.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-devtools</artifactId>
      <optional>true</optional>
    </dependency>
    <dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-neo4j</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

我尝试根据本指南调整版本:https://neo4j.com/developer/neo4j-ogm/

这是我的依赖关系树:

[INFO] mygroup:myapp:jar:0.0.1-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter:jar:1.5.9.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot:jar:1.5.9.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-autoconfigure:jar:1.5.9.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-logging:jar:1.5.9.RELEASE:compile
[INFO] |  |  +- ch.qos.logback:logback-classic:jar:1.1.11:compile
[INFO] |  |  |  \- ch.qos.logback:logback-core:jar:1.1.11:compile
[INFO] |  |  +- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] |  |  \- org.slf4j:log4j-over-slf4j:jar:1.7.25:compile
[INFO] |  +- org.springframework:spring-core:jar:4.3.13.RELEASE:compile
[INFO] |  \- org.yaml:snakeyaml:jar:1.17:runtime
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.5.9.RELEASE:compile
[INFO] |  +- org.springframework.boot:spring-boot-starter-tomcat:jar:1.5.9.RELEASE:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.23:compile
[INFO] |  |  |  \- org.apache.tomcat:tomcat-annotations-api:jar:8.5.23:compile
[INFO] |  |  +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.23:compile
[INFO] |  |  \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.23:compile
[INFO] |  +- org.hibernate:hibernate-validator:jar:5.3.6.Final:compile
[INFO] |  |  +- javax.validation:validation-api:jar:1.1.0.Final:compile
[INFO] |  |  +- org.jboss.logging:jboss-logging:jar:3.3.1.Final:compile
[INFO] |  |  \- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.8.10:compile
[INFO] |  |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.8.0:compile
[INFO] |  |  \- com.fasterxml.jackson.core:jackson-core:jar:2.8.10:compile
[INFO] |  +- org.springframework:spring-web:jar:4.3.13.RELEASE:compile
[INFO] |  |  \- org.springframework:spring-aop:jar:4.3.13.RELEASE:compile
[INFO] |  \- org.springframework:spring-webmvc:jar:4.3.13.RELEASE:compile
[INFO] |     \- org.springframework:spring-expression:jar:4.3.13.RELEASE:compile
[INFO] +- org.springframework.boot:spring-boot-devtools:jar:1.5.9.RELEASE:compile
[INFO] +- org.springframework.data:spring-data-neo4j:jar:4.2.9.RELEASE:compile
[INFO] |  +- org.springframework:spring-tx:jar:4.3.13.RELEASE:compile
[INFO] |  +- org.springframework:spring-context:jar:4.3.13.RELEASE:compile
[INFO] |  +- org.springframework:spring-beans:jar:4.3.13.RELEASE:compile
[INFO] |  +- org.slf4j:jcl-over-slf4j:jar:1.7.25:compile
[INFO] |  +- org.springframework.data:spring-data-commons:jar:1.13.9.RELEASE:compile
[INFO] |  +- org.neo4j:neo4j-ogm-core:jar:2.1.5:compile
[INFO] |  |  +- org.neo4j:neo4j-ogm-api:jar:2.1.5:compile
[INFO] |  |  |  \- commons-codec:commons-codec:jar:1.10:compile
[INFO] |  |  +- org.neo4j:neo4j-ogm-compiler:jar:2.1.5:compile
[INFO] |  |  +- org.apache.commons:commons-lang3:jar:3.4:compile
[INFO] |  |  \- org.apache.commons:commons-collections4:jar:4.1:compile
[INFO] |  +- org.neo4j:neo4j-ogm-http-driver:jar:2.1.5:compile
[INFO] |  |  +- org.apache.httpcomponents:httpclient:jar:4.5.3:compile
[INFO] |  |  |  \- org.apache.httpcomponents:httpcore:jar:4.4.8:compile
[INFO] |  |  \- commons-io:commons-io:jar:2.4:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] \- org.springframework.boot:spring-boot-starter-test:jar:1.5.9.RELEASE:test
[INFO]    +- org.springframework.boot:spring-boot-test:jar:1.5.9.RELEASE:test
[INFO]    +- org.springframework.boot:spring-boot-test-autoconfigure:jar:1.5.9.RELEASE:test
[INFO]    +- com.jayway.jsonpath:json-path:jar:2.2.0:test
[INFO]    |  \- net.minidev:json-smart:jar:2.2.1:test
[INFO]    |     \- net.minidev:accessors-smart:jar:1.1:test
[INFO]    |        \- org.ow2.asm:asm:jar:5.0.3:test
[INFO]    +- junit:junit:jar:4.12:test
[INFO]    +- org.assertj:assertj-core:jar:2.6.0:test
[INFO]    +- org.mockito:mockito-core:jar:1.10.19:test
[INFO]    |  \- org.objenesis:objenesis:jar:2.1:test
[INFO]    +- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO]    +- org.hamcrest:hamcrest-library:jar:1.3:test
[INFO]    +- org.skyscreamer:jsonassert:jar:1.4.0:test
[INFO]    |  \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO]    \- org.springframework:spring-test:jar:4.3.13.RELEASE:test

抱歉,我也是 Java 新手,所以请帮助指导我尝试其他事情,因为我完全不熟悉 Java 生态系统。

感谢您的宝贵时间! :)

好的,我已经准备好了一切。抱歉,对于写得不好的问题,因为我完全迷路了,不知道如何构建事物。我仍然可能遗漏了一些关键的 Java 背景知识并且可能是错误的,但希望正确的信息多于错误的信息。

以下是最终让我进入工作状态的原因,以防对其他人有所帮助: 我发现本教程: https://neo4j.com/developer/spring-data-neo4j/ 有一些错误导致我偏离了多个切线。

public class PersistenceContext { // needs to extend if using @Override
    @Override // needs to be @Bean if not extending
    public SessionFactory getSessionFactory() {
        return new SessionFactory("org.neo4j.cineasts.domain");
    }
}

最终起作用的是以下 configuration/tutorial: https://spring.io/guides/gs/accessing-data-neo4j/#_permissions_to_access_neo4j

这个例子:https://github.com/neo4j-examples/movies-java-spring-data-neo4j/blob/master/src/main/resources/application.properties

有了这些缺失的部分,我终于能够使用 Spring-Data-Neo4j 实现 Spring-Boot 的工作实现。我的主要目标是按照本指南使用当前最新版本 Spring-Boot 1.5.9 和 Neo4j-OGM 2.1.5: https://neo4j.com/developer/neo4j-ogm/#_compatibility

祝你好运! :)