springboot集成neo4j版本5.2.0

  1. 引入compile('org.springframework.boot:spring-boot-starter-data-neo4j')

application.properties中加入配置如下:

spring.data.neo4j.uri = bolt://192.168.xx.xxx:7687

spring.data.neo4j.username = username

spring.data.neo4j.password = password

@Data

@NodeEntity("Device")

public class DeviceNode {

@Id

@GeneratedValue

private Long id;

private String deviceId;

}

@Repository

public interface DeviceRepository extends Neo4jRepository<DeviceNode, Long> {

}

Controller里面存储节点

DeviceNode deviceNode = new DeviceNode();

deviceNode.setDeviceId("1233445677");

deviceRepository.save(deviceNode);

  1. springboot 2.2.1.RELEASE 版本集成neo4j最新版本5.2.0报错:

{

"timestamp": "2023-01-05T05:17:07.772+0000",

"status": 500,

"error": "Internal Server Error",

"message": "Cypher execution failed with code 'Neo.ClientError.Statement.SyntaxError': Invalid input '{': expected \"+\" or \"-\" (line 1, column 8 (offset: 7))\n\"UNWIND {rows} as row CREATE (n:`Device`) SET n=row.props RETURN row.nodeRef as ref, ID(n) as id, {type} as type\"\n ^.; nested exception is org.neo4j.ogm.exception.CypherException: Cypher execution failed with code 'Neo.ClientError.Statement.SyntaxError': Invalid input '{': expected \"+\" or \"-\" (line 1, column 8 (offset: 7))\n\"UNWIND {rows} as row CREATE (n:`Device`) SET n=row.props RETURN row.nodeRef as ref, ID(n) as id, {type} as type\"\n ^.",

"path": "/api/v1/passengerPic/add"

}

了解下来应该是springboot与neo4j版本兼容问题,springboot升级到2.3.1.RELEASE版本之后,问题解决。

{

"msg": "ok",

"code": 1,

"succ": true,

"oper": "default"

}

值得注意的是,官方文档推荐的springboot版本是2.6.3

  1. springboot启动不了,报错:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.

2023-01-05 13:55:59.830 [main] ERROR o.s.b.d.LoggingFailureAnalysisReporter -

***************************

APPLICATION FAILED TO START

***************************

Description:

The bean 'sessionFactory', defined in class path resource [org/springframework/boot/autoconfigure/data/neo4j/Neo4jDataAutoConfiguration$Neo4jOgmSessionFactoryConfiguration.class], could not be registered. A bean with that name has already been defined in class path resource [org/apache/shiro/spring/config/web/autoconfigure/ShiroWebAutoConfiguration.class] and overriding is disabled.

Action:

Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true

Disconnected from the target VM, address: '127.0.0.1:60117', transport: 'socket'

Process finished with exit code 1

这是项目已经集成了shiro,有相同的bean sessionFactory生成。

按照提示在配置文件中application.properties中设置

spring.main.allow-bean-definition-overriding = true即可

  1. 本地编译的gradle版本为4.10.1,会出现以下问题,升级到6.3之后问题解决。

> Failed to apply plugin [id 'org.springframework.boot']

> Spring Boot plugin requires Gradle 5 (5.6.x only) or Gradle 6 (6.3 or later). The current version is Gradle 4.10.1

gradle官网下载地址:https://gradle.org/releases/

参考文档:https://blog.csdn.net/wang0112233/article/details/117995424

参考文档:https://docs.spring.io/spring-data/neo4j/docs/current/reference/html/#getting-started

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring Boot集成Neo4j需要进行以下步骤: 1. 添加依赖:在`pom.xml`文件中添加Neo4j的依赖。 ```xml <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-neo4j</artifactId> </dependency> ``` 2. 配置数据源:在`application.properties`文件中配置Neo4j的连接信息。 ```properties spring.data.neo4j.uri=bolt://localhost:7687 spring.data.neo4j.username=neo4j spring.data.neo4j.password=password ``` 3. 创建实体类:创建表示节点以及关系的实体类。 ```java @NodeEntity public class Person { @Id @GeneratedValue private Long id; private String name; // 省略getter和setter方法 } @RelationshipEntity(type = "FRIEND") public class Friendship { @Id @GeneratedValue private Long id; @StartNode private Person person1; @EndNode private Person person2; // 省略getter和setter方法 } ``` 4. 创建Repository:创建用于操作数据库的Repository接口。 ```java public interface PersonRepository extends Neo4jRepository<Person, Long> { // 自定义查询方法 } ``` 5. 使用Repository:在需要使用Neo4j的地方注入Repository,进行CRUD操作。 ```java @Service public class PersonService { private final PersonRepository personRepository; public PersonService(PersonRepository personRepository) { this.personRepository = personRepository; } public void savePerson(Person person) { personRepository.save(person); } // 其他操作方法 } ``` 这样就完成了Spring BootNeo4j集成。你可以根据需要自定义Repository的方法,也可以使用Spring Data Neo4j提供的方法进行操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值