五、Neo4j-在springboot项目使用

本文介绍了如何在SpringBoot项目中集成Neo4j,包括在build.gradle中添加依赖,配置db.yml以设置Neo4j数据源,创建配置类,定义节点和关系的实体类,以及对应的repository接口。此外,还提到了查询结果类的编写,以处理查询返回的特定结果。
摘要由CSDN通过智能技术生成

(1) build.gradle   jar包引用

//neo4j
 implementation "org.springframework.boot:spring-boot-starter-data-neo4j"

(2) db.yml     neo4j数据源配置 

# 数据源配置
spring:
  data:
    neo4j:
      uri: bolt://127.0.0.1:7687
      database: neo4j
      username: neo4j
      password: pwd

(3)配置类

/*
 * Copyright (c) 2020, Shinow All rights reserved.
 * Shinow PROPRIETARY/CONFIDENTIAL.
 */
package com.shinow.id.config;

import org.neo4j.ogm.session.SessionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
import org.springframework.data.neo4j.transaction.Neo4jTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * 类说明:neo4j配置
 *
 * @author zlw
 * @version 1.0
 * @date 2021/11/22 09:35
 * @since JDK 14.0.2 jdk
 */
@Configuration
@EnableNeo4jRepositories(basePackages = "com.shinow.id.repository")
@EntityScan(basePackages = "com.shinow.id.graph")
@EnableTransactionManagement
public class Neo4jConfig {
    /**
     * uri
     */
    @Value("${spring.data.neo4j.uri}")
    private String uri;
    /**
     * username
     */
    @Value("${spring.data.neo4j.username}")
    private String username;
    /**
     * password
     */
    @Value("${spring.data.neo4j.password}")
    private String password;
    @Bean
    public org.neo4j.ogm.config.Configuration configuration() {
        org.neo4j.ogm.config.Configuration configuration = new org.neo4j.ogm.config.Configuration.Builder()
                .uri(uri)
                .credentials(username, password)
                .build()
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值