gpt4 book ai didi

java - 使用 Neo4Jconfiguration 连接 Neo4J 与 Spring boot 时发生未经授权的异常

转载 作者:行者123 更新时间:2023-11-29 06:58:59 29 4
gpt4 key购买 nike

您好,我正在尝试编写一个微服务,我创建了一个简单的 spring boot 应用程序,它使用 Neo4JConfiguration 进行扩展。我可以成功运行并且服务器从目标端口启动但是通过点击 api 内部错误在浏览器中抛出

白标错误页面 此应用程序没有/error 的显式映射,因此您将其视为后备。

There was an unexpected error (type=Internal Server Error, status=500).
org.springframework.web.util.NestedServletException: Request processing failed;
nested exception is org.neo4j.ogm.session.result.ResultProcessingException:
Failed to execute request:
{"statements":[{"statement":"MATCH p=(n)-[*0..1]-(m) WHERE id(n) = { id } RETURN collect(distinct p)",
"parameters":{"id":1},"resultDataContents":["graph"]}]}

而我的 mvn 控制台错误清楚地表明 session 尚未获得授权。错误:

12:12:19.114 [qtp212459676-16] INFO  org.neo4j.ogm.session.Neo4jSession - There is no existing transaction, creating a transient one
12:12:19.272 [qtp212459676-16] INFO o.n.o.session.request.DefaultRequest - POST http://localhost:7474/db/data/transaction/commit, request: {"statements":[{"statement":"MATCH p=(n)-[*0..1]-(m) WHERE id(n) = { id } RETURN collect(distinct p)","parameters":{"id":1},"resultDataContents":["graph"]}]}
**caught response exception: Unauthorized**
12:12:19.606 [qtp212459676-16] INFO o.s.d.n.config.Neo4jConfiguration - Intercepted exception
12:12:19.642 [qtp212459676-16] WARN o.e.jetty.servlet.ServletHandler -
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.neo4j.ogm.session.result.ResultProcessingException: Failed to execute request: {"statements":[{"statement":"MATCH p=(n)-[*0..1]-(m) WHERE id(n) = { id } RETURN collect(distinct p)","parameters":{"id":1},"resultDataContents":["graph"]}]}

谁能告诉我如何使用 springboot 授权 neo4j 吗?

这是我与 Neo4J 实例连接的 bean。

@Override
@Bean
public Neo4jServer neo4jServer() {
// log.info("Initialising server connection");
return new RemoteServer("http://localhost:7474");
//return new InProcessServer();
}

@Override
@Bean
public SessionFactory getSessionFactory() {
log.info("Initialising Session Factory");
return new SessionFactory("nuclei.domain");
}

@Override
@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public Session getSession() throws Exception {
log.info("Initialising session-scoped Session Bean");
return super.getSession();
}

如何在这里设置用户名/密码?

如果能得到我问题的标准解决方案,我将不胜感激。谢谢。

最佳答案

我现在已经成功连接到数据库了。以下是我添加的系统属性部分。

@Override
@Bean
public SessionFactory getSessionFactory() {
log.info("Initialising Session Factory");
System.setProperty("username", "neo4j");
System.setProperty("password", "root");
return new SessionFactory("nuclei.domain");
}

在获取 session 工厂之前需要将凭据添加到 sys 属性。为了良好实践,我将凭据带回我的配置文件并将其加载到系统属性。

关于java - 使用 Neo4Jconfiguration 连接 Neo4J 与 Spring boot 时发生未经授权的异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29407409/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com