Java 使用带有Spring boot的Neo4J配置连接Neo4J时出现未经授权的异常
大家好,我正在尝试编写一个微服务,我已经创建了一个简单的spring引导应用程序,它通过Neo4JCConfiguration进行扩展。我可以运行成功,服务器以目标端口启动,但通过点击api,内部错误会在浏览器中抛出 白标错误页 此应用程序没有/error的显式映射,因此您将其视为回退Java 使用带有Spring boot的Neo4J配置连接Neo4J时出现未经授权的异常,java,spring,spring-boot,spring-data-neo4j,Java,Spring,Spring Boot,Spring Data Neo4j,大家好,我正在尝试编写一个微服务,我已经创建了一个简单的spring引导应用程序,它通过Neo4JCConfiguration进行扩展。我可以运行成功,服务器以目标端口启动,但通过点击api,内部错误会在浏览器中抛出 白标错误页 此应用程序没有/error的显式映射,因此您将其视为回退 There was an unexpected error (type=Internal Server Error, status=500). org.springframework.web.util.N
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控制台的错误明确地表明会话未被授权。错误:
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
下面是我的bean与Neo4J实例的连接
@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();
}
如何在此处设置用户名/密码
如果得到我的问题的PAR解决方案,我很感激。谢谢。您可以将它们指定为系统属性。见org.neo4j.ogm.authentication.CredentialsService;e、 g.-Dusername=neo4j-Dpassword=您的_密码您可以将它们指定为系统属性。见org.neo4j.ogm.authentication.CredentialsService;e、 g.-Dusername=neo4j-Dpassword=您的_密码我现在已成功连接到数据库。以下是我添加了系统属性的部分
@Override
@Bean
public SessionFactory getSessionFactory() {
log.info("Initialising Session Factory");
System.setProperty("username", "neo4j");
System.setProperty("password", "root");
return new SessionFactory("nuclei.domain");
}
在获取会话工厂之前,需要将凭据添加到sys属性。出于良好的实践,我将凭据带回配置文件并将其加载到系统属性 我现在已成功连接到数据库。以下是我添加了系统属性的部分
@Override
@Bean
public SessionFactory getSessionFactory() {
log.info("Initialising Session Factory");
System.setProperty("username", "neo4j");
System.setProperty("password", "root");
return new SessionFactory("nuclei.domain");
}
在获取会话工厂之前,需要将凭据添加到sys属性。出于良好的实践,我将凭据带回配置文件并将其加载到系统属性 使用迄今为止的最新版本
@Override
@Bean
public SessionFactory getSessionFactory() {
log.info("Initialising Session Factory");
System.setProperty("username", "neo4j");
System.setProperty("password", "root");
return new SessionFactory("nuclei.domain");
}
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm</artifactId>
<version>1.1.4</version>
</dependency>
2.在URL中嵌入连接凭据
SessionFactory sessionFactory = new SessionFactory("org.neo4j.example.domain");
Session session = sessionFactory.openSession("http://username:password@localhost:7474");
3.设置系统属性
System.setProperty("username", user);
System.setProperty("password", pass);
SessionFactory sessionFactory = new SessionFactory("org.neo4j.example.domain");
Session session = sessionFactory.openSession("http://localhost:7474");
使用迄今为止的最新版本
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm</artifactId>
<version>1.1.4</version>
</dependency>
2.在URL中嵌入连接凭据
SessionFactory sessionFactory = new SessionFactory("org.neo4j.example.domain");
Session session = sessionFactory.openSession("http://username:password@localhost:7474");
3.设置系统属性
System.setProperty("username", user);
System.setProperty("password", pass);
SessionFactory sessionFactory = new SessionFactory("org.neo4j.example.domain");
Session session = sessionFactory.openSession("http://localhost:7474");
那个例子是什么?域?第二个选项解决了我的问题,尽管我需要将localhost更改为127.0.0.1。那个例子是什么。域?第二个选项解决了我的问题,尽管我需要将localhost更改为127.0.0.1