neo4j会话存在打开的连接

3z6pesqy  于 2021-07-03  发布在  Java
关注(0)|答案(0)|浏览(250)

我使用neo4jv4.0.1和springbootv.2.2.4构建我的应用程序
这是我的neo4j会话配置

package net.skycloud.cmdb.common.config.neo4j;

import org.neo4j.driver.AuthTokens;
import org.neo4j.driver.Driver;
import org.neo4j.driver.GraphDatabase;
import org.neo4j.driver.Session;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: fangcong
 * @description:
 * @create: Created by work on 2020-03-05 00:10

**/

@Configuration
public class Neo4jConfig{

    @Value("${spring.data.neo4j.uri}")
    private String databaseUrl;

    @Value("${spring.data.neo4j.username}")
    private String userName;

    @Value("${spring.data.neo4j.password}")
    private String password;

    @Bean
    public Driver neo4jDriver() {
        return GraphDatabase.driver(databaseUrl, AuthTokens.basic(userName,password));
    }

    @Bean
    public Session getSession() {
       return neo4jDriver().session();
    }

}

我使用session.run(query)查询数据这是我的代码

public List<Node> nodeSearch(String jql, String username) throws SyntaxErrorException {
        List<Node> nodes = new ArrayList<>();
        JqlSyntaxTransformer transformer = new JqlSyntaxTransformer();
        String cypher;
        try {
            cypher = transformer.execute(jql).get(0).toCypher();
            Result result = session.run(cypher);
            if (result.hasNext()) {
                List<Node> list = result.list(x -> new Node(x.values().get(0).asNode()));
                nodes.addAll(list);
            }
        } catch (RuntimeException e) {
            logger.error(e.getMessage(), e);
            throw new SyntaxErrorException(e.getMessage());
        }
        .......
        .......
        .......
    }

当我运行我的应用程序时,我发现了一个错误,这个错误有时会发生这是我的错误图片在这里输入图片说明
春暖花开的豆子不是由德法卢特独生子吗?我怎样才能纠正这个错误,非常感谢

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题