SpringBoot集成Neo4j调试的时候报:
org.neo4j.driver.exceptions.ClientException: The server does not support any of the protocol versions supported by this driver. Ensure that you are using driver and server versions that are compatible with one another.
在网络上查找解决方法未果,但是看得出是驱动程序和服务器版本彼此不兼容的问题,由于服务器的JDK是1.8的,所以最初没有部署最新版本的neo4j(报错时使用的版本是3.4.5),调试项目的依赖版本调整也无法解决问题,最终重新部署了(openjdk-11+28 和 neo4j-4.2.7)才解决问题。
1.依赖及配置
<!-- springboot 版本 2.5.1 --> <!--neo4j--> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-neo4j</artifactId> </dependency> <!-- neo4j-ogm-http-driver --> <dependency> <groupId>org.neo4j</groupId> <artifactId>neo4j-ogm-http-driver</artifactId> <version>2.1.5</version> </dependency>
密码是必须修改的
spring: neo4j: uri: bolt://aliyun:7687 authentication: username: neo4j password: neo4j1
2.源代码
/** * 部门类 */ @NodeEntity(label = "dept") @Data @Builder public class Dept { @Id @GeneratedValue private Long id; @Property(name = "deptName") private String deptName; } /** * 关系类 */ @RelationshipEntity(type = "relationShip") @Data @Builder public class RelationShip { @Id @GeneratedValue private Long id; @StartNode private Dept parent; @EndNode private Dept child; } /** * 两个继承Neo4jRepository的接口 */ @Repository public interface DeptRepository extends Neo4jRepository<Dept,Long> {} @Repository public interface RelationShipRepository extends Neo4jRepository<RelationShip, Long> {} /** * 测试方法类 */ @RestController public class TestController { @Autowired private DeptRepository deptRepository; @Autowired private RelationShipRepository relationShipRepository; @GetMapping("create") public void create() { Dept root = Dept.builder().deptName("软件部").build(); Dept dept1 = Dept.builder().deptName("架构组").build(); Dept dept2 = Dept.builder().deptName("开发组").build(); Dept dept3 = Dept.builder().deptName("实施组").build(); Dept dept21 = Dept.builder().deptName("前端技术部").build(); Dept dept22 = Dept.builder().deptName("后端技术部").build(); Dept dept23 = Dept.builder().deptName("测试技术部").build(); List<Dept> deptList = new ArrayList<>(Arrays.asList(root, dept1, dept2, dept3, dept21, dept22, dept23)); deptRepository.saveAll(deptList); RelationShip relationShip1 = RelationShip.builder().parent(root).child(dept1).build(); RelationShip relationShip2 = RelationShip.builder().parent(root).child(dept2).build(); RelationShip relationShip3 = RelationShip.builder().parent(root).child(dept3).build(); RelationShip relationShip21 = RelationShip.builder().parent(dept2).child(dept21).build(); RelationShip relationShip22 = RelationShip.builder().parent(dept2).child(dept22).build(); RelationShip relationShip23 = RelationShip.builder().parent(dept2).child(dept23).build(); List<RelationShip> relationShipList = new ArrayList<>(Arrays.asList(relationShip1, relationShip2, relationShip3, relationShip21, relationShip22, relationShip23)); relationShipRepository.saveAll(relationShipList); } @GetMapping("deleteAll") public void deleteAll() { deptRepository.deleteAll(); relationShipRepository.deleteAll(); } }
3.结果
4.总结
回想一下,我是不是应该先测试一下不同版本的依赖再去重新部署呢?