正如标题所示,我在使用mybatis连接springboot中的neo4j时遇到了stackoverflow问题。cql在neo4j桌面上运行得很好,但是api在mapper中使用相同的cql返回500个结果。
错误消息如下:
2020-12-31 20:22:24.560 ERROR 31232 --- [nio-9090-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Handler dispatch failed; nested exception is java.lang.StackOverflowError] with root cause
java.lang.StackOverflowError: null
at java.io.WinNTFileSystem.normalizePrefix(WinNTFileSystem.java:186) ~[na:1.8.0_261]
at java.io.WinNTFileSystem.normalize(WinNTFileSystem.java:111) ~[na:1.8.0_261]
at java.io.WinNTFileSystem.normalize(WinNTFileSystem.java:93) ~[na:1.8.0_261]
at java.io.File.<init>(File.java:279) ~[na:1.8.0_261]
at java.io.FilePermission$1.run(FilePermission.java:224) ~[na:1.8.0_261]
at java.io.FilePermission$1.run(FilePermission.java:212) ~[na:1.8.0_261]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_261]
at java.io.FilePermission.init(FilePermission.java:212) ~[na:1.8.0_261]
at java.io.FilePermission.<init>(FilePermission.java:299) ~[na:1.8.0_261]
at sun.net.www.protocol.file.FileURLConnection.getPermission(FileURLConnection.java:228) ~[na:1.8.0_261]
at sun.net.www.protocol.jar.JarFileFactory.getPermission(JarFileFactory.java:166) ~[na:1.8.0_261]
at sun.net.www.protocol.jar.JarFileFactory.getCachedJarFile(JarFileFactory.java:136) ~[na:1.8.0_261]
at sun.net.www.protocol.jar.JarFileFactory.get(JarFileFactory.java:91) ~[na:1.8.0_261]
at sun.net.www.protocol.jar.JarURLConnection.connect(JarURLConnection.java:122) ~[na:1.8.0_261]
at sun.net.www.protocol.jar.JarURLConnection.getInputStream(JarURLConnection.java:152) ~[na:1.8.0_261]
at java.net.URLClassLoader.getResourceAsStream(URLClassLoader.java:239) ~[na:1.8.0_261]
at java.lang.Class.getResourceAsStream(Class.java:2223) ~[na:1.8.0_261]
at org.neo4j.jdbc.DatabaseMetaData.<init>(DatabaseMetaData.java:100) ~[neo4j-jdbc-driver-3.1.0.jar:na]
at org.neo4j.jdbc.http.HttpDatabaseMetaData.<init>(HttpDatabaseMetaData.java:34) ~[neo4j-jdbc-driver-3.1.0.jar:na]
at org.neo4j.jdbc.http.HttpDatabaseMetaData.<init>(HttpDatabaseMetaData.java:43) ~[neo4j-jdbc-driver-3.1.0.jar:na]
at org.neo4j.jdbc.http.HttpConnection.getMetaData(HttpConnection.java:105) ~[neo4j-jdbc-driver-3.1.0.jar:na]
at org.neo4j.jdbc.http.HttpConnection.getMetaData(HttpConnection.java:40) ~[neo4j-jdbc-driver-3.1.0.jar:na]
at com.zaxxer.hikari.pool.ProxyConnection.getMetaData(ProxyConnection.java:380) ~[HikariCP-3.4.5.jar:na]
at com.zaxxer.hikari.pool.HikariProxyConnection.getMetaData(HikariProxyConnection.java) ~[HikariCP-3.4.5.jar:na]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getNextResultSet(DefaultResultSetHandler.java:256) ~[mybatis-3.5.2.jar:3.5.2]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getNextResultSet(DefaultResultSetHandler.java:261) ~[mybatis-3.5.2.jar:3.5.2]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getNextResultSet(DefaultResultSetHandler.java:261) ~[mybatis-3.5.2.jar:3.5.2]
at org.apache.ibatis.executor.resultset.DefaultResultSetHandler.getNextResultSet(DefaultResultSetHandler.java:261) ~[mybatis-3.5.2.jar:3.5.2]
(最后一行重复了几百次)
以下是我的配置和代码:
pom.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.neo4j.dw</groupId>
<artifactId>dw</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>amazonMovies</name>
<description>Amazon Movies Data Warehouse</description>
<!-- <properties>-->
<!-- <java.version>1.8</java.version>-->
<!-- </properties>-->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-neo4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Neo4j-->
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-jdbc-driver</artifactId>
<version>3.1.0</version>
</dependency>
<!-- mybatis-->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.5.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<!-- solve: java.lang.NumberFormatException: For input string: "" -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-bean-validators</artifactId>
<version>2.9.2</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<!-- mp -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.4.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-generator</artifactId>
<version>3.4.0</version>
<exclusions>
<exclusion>
<artifactId>mybatis</artifactId>
<groupId>org.mybatis</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.auth0</groupId>
<artifactId>java-jwt</artifactId>
<version>3.9.0</version>
</dependency>
<!-- fastjson -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.47</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20190722</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk16</artifactId>
<version>1.46</version>
</dependency>
<!--分页插件 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus</artifactId>
<version>3.4.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>com.neo4j.dw.DwApplication</mainClass>
<excludes>
<exclude>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
</project>
mybatis\ u config.xml文件
<?xml version="1.0" encoding="UTF8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="org.neo4j.jdbc.http.HttpDriver"/>
<property name="url" value="jdbc:neo4j:http://localhost:7474"/>
<property name="username" value="neo4j"/>
<property name="password" value="ETL2020"/>
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="./mapper/*.xml"/>
</mappers>
</configuration>
应用程序.yml
spring:
datasource:
driver-class-name: org.neo4j.jdbc.http.HttpDriver
url: jdbc:neo4j:http://localhost:7474
username: neo4j
password: ETL2020
mybatis-plus:
mapper-locations: classpath*:/mapper/**Mapper.xml
type-aliases-package: com.neo4j.dw.Model
server:
port: 9090
测试控制器
package com.neo4j.dw.Controller;
import com.neo4j.dw.Model.User;
import com.neo4j.dw.Service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
@RestController
@RequestMapping("/test")
public class TestController {
@Autowired
private TestService testService;
@GetMapping("/hello")
public String hello(){
return "hello";
}
@GetMapping("/user")
public ArrayList<User> getUsers() {
return testService.selectUsers();
}
}
测试服务实现
package com.neo4j.dw.Service.Impl;
import com.neo4j.dw.Mapper.TestMapper;
import com.neo4j.dw.Model.User;
import com.neo4j.dw.Service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
@Service
public class TestServiceImpl implements TestService {
@Autowired
private TestMapper testMapper;
@Override
public ArrayList<User> selectUsers(){
return testMapper.selectUsers();
}
}
测试Map器
package com.neo4j.dw.Mapper;
import com.neo4j.dw.Model.User;
import org.apache.ibatis.annotations.Mapper;
import java.util.ArrayList;
@Mapper
public interface TestMapper {
ArrayList<User> selectUsers();
}
用户
package com.neo4j.dw.Model;
import lombok.*;
import com.baomidou.mybatisplus.annotation.TableField;
@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
@Getter
@Setter
public class User {
@TableField("userId")
public String userId;
@TableField("profileName")
public String profileName;
}
testmapper.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.neo4j.dw.Mapper.TestMapper">
<select id="selectUsers" resultType="int">
MATCH (n1)-[r]->(n2) RETURN count(*)
</select>
</mapper>
我是neo4j和mybatis的新手。有人能帮我解决这个错误吗?万分感谢!
1条答案
按热度按时间nafvub8i1#
据我所知,在以下方面没有mybatis整合:
Spring Data neo4j 5(通过
spring-boot-starter-data-neo4j
在您的pom中,包括直到spring boot 2.3)nor neo4j ogm(neo4j5所建立的spring数据库)。
如果您想开始,您可能应该从springdataneo4j6(又名sdn6)开始,即编写本文时springdataneo4j的最新版本。如果您将spring-boot升级到最新版本(编写本文时为2.4),您将自动获得它。
您可能应该从sdn6的参考文档开始。你也可以在这里找到一个例子。
正如您将了解到的,您可以摆脱mybatis,sdn6(和通过neo4j ogm的5)已经开始处理Map了。