Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在SDN 5.0.0中创建neo4j sessionfactory_Java_Spring_Spring Boot_Spring Data Neo4j_Spring Data Neo4j 5 - Fatal编程技术网

Java 在SDN 5.0.0中创建neo4j sessionfactory

Java 在SDN 5.0.0中创建neo4j sessionfactory,java,spring,spring-boot,spring-data-neo4j,spring-data-neo4j-5,Java,Spring,Spring Boot,Spring Data Neo4j,Spring Data Neo4j 5,背景 我有一个Maven,Spring data Neo4j项目。它发布并获取单个对象。我正在尝试添加会话,但遇到错误 有以下文件: 他们建议: @Configuration @EnableNeo4jRepositories(basePackages = "org.neo4j.example.repository") @EnableTransactionManagement public class MyConfiguration { @Bean public SessionF

背景

我有一个Maven,Spring data Neo4j项目。它发布并获取单个对象。我正在尝试添加会话,但遇到错误

有以下文件:

他们建议:

@Configuration
@EnableNeo4jRepositories(basePackages = "org.neo4j.example.repository")
@EnableTransactionManagement
public class MyConfiguration {

    @Bean
    public SessionFactory sessionFactory() {
        // with domain entity base package(s)
        return new SessionFactory(configuration(), "org.neo4j.example.domain");
    }

    @Bean
    public org.neo4j.ogm.config.Configuration configuration() {
        ConfigurationSource properties = new ClasspathConfigurationSource("ogm.properties");
        org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration.Builder(properties)
        return configuration;
    }

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

}
但是当我复制第二个
@Bean
时,我的eclipse将:
new org.neo4j.ogm.config.Configuration.Builder(properties)
标记为红色,并建议我将类型配置更改为Builder。然后继续建议更改,直到第二个
@Bean
看起来像:

@Bean
public Builder configuration() {
    ConfigurationSource properties = new ClasspathConfigurationSource("ogm.properties");
    Builder configuration = new org.neo4j.ogm.config.Configuration.Builder(properties);
    return configuration;
}
但是第一个
@Bean
停止工作,因为它需要
配置()

问题

那么,当当前文档的建议不起作用时,如何添加sessionfactory呢?我看过许多其他示例,但它们都使用了较旧的版本,其中包含不推荐的内容,如
Neo4jConfiguration

注释

My pom.xml没有父项,并且这些依赖项和存储库:

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-neo4j</artifactId>
        <version>5.0.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>2.0.0.M3</version>
    </dependency>



<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot</artifactId>
        <version>2.0.0.M3</version>
    </dependency>

    <dependency>
        <groupId>com.voodoodyne.jackson.jsog</groupId>
        <artifactId>jackson-jsog</artifactId>
        <version>1.1</version>
        <scope>compile</scope>
    </dependency>



  </dependencies>



  <repositories>
    <repository>
        <id>spring-libs-release</id>
        <name>Spring Releases</name>
        <url>https://repo.spring.io/libs-release</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>
导致此错误的原因:

 ...Factory method 'configuration' threw exception; nested exception is java.lang.NullPointerException
我的
ogm.properties
文件是:

server.port=8585
spring.data.neo4j.uri=bolt://localhost
spring.data.neo4j.username=myuser
spring.data.neo4j.password=mypass

您的初始配置看起来不错,只是在生成器实例化之后缺少了一个
.build()
(这是文档中的一个输入错误)

因此,配置init应该是:

new org.neo4j.ogm.config.Configuration.Builder(properties).build();
关于第二条:您不能混合使用SDN样式配置和Spring Boot自动配置

或者您使用SDN样式(与第一个代码片段一样),并且
ogm.properties
文件如下所示:

URI=bolt://localhost
username=myUser
password=myPassword
范例

使用Spring引导自动配置,则无需在配置类中声明配置、sessionFactory和事务管理器。只需使用注释对配置进行注释

@EnableNeo4jRepositories("com.myproject.repository")
@EntityScan(basePackages = "com.myproject.domain")
并使用spring引导属性格式:

spring.data.neo4j.uri=bolt://localhost
spring.data.neo4j.username=myuser
spring.data.neo4j.password=mypass
范例

关于
NullPointerException
:这是因为在类路径中找不到
ogm.properties
文件

spring.data.neo4j.uri=bolt://localhost
spring.data.neo4j.username=myuser
spring.data.neo4j.password=mypass