当前位置:   article > 正文

springboot集成neo4j版本5.2.0_spring boot整合neo4j5版本

spring boot整合neo4j5版本
  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

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/641494
推荐阅读
相关标签
  

闽ICP备14008679号