2015-04-02 99 views
1

嗨我正在尝试编写一个微服务,我创建了一个简单的使用Neo4JConfiguration进行扩展的Spring引导应用程序。我可以运行成功和服务器开始与目标端口,但通过点击api内部错误抛出浏览器使用Neo4J配置与Spring引导连接Neo4J时未经授权的异常

白色标签错误页面 此应用程序没有明确映射/错误,所以你看到这是一个后备。

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(); 
} 

如何在此处设置用户名/密码?

我很感激如果得到我问题的解决方案。谢谢。

回答

2

您可以将它们指定为系统属性。见org.neo4j.ogm.authentication.CredentialsService;例如-Dusername=neo4j -Dpassword=your_password

+0

我想知道我在哪里可以应用这些系统属性。 – Sathish 2015-04-07 08:53:23

3

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

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

需要得到会话factory.For我带回来的凭证到我的配置文件,并将其加载到系统属性中的好的做法之前添加凭据SYS性能。

1

使用最新版本迄今

<dependency> 
    <groupId>org.neo4j</groupId> 
    <artifactId>neo4j-ogm</artifactId> 
    <version>1.1.4</version> 
</dependency> 

使您连接到的Neo4j使用以下方法

1.Passing连接凭证会议开幕

SessionFactory sessionFactory = new SessionFactory("org.neo4j.example.domain"); 
Session session = sessionFactory.openSession("http://localhost:7474", username, password); 

2时。在URL中嵌入连接凭证

SessionFactory sessionFactory = new SessionFactory("org.neo4j.example.domain"); 
Session session = sessionFactory.openSession("http://username:[email protected]: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"); 
+0

这个example.domain是什么? – Udhaya 2016-08-23 06:54:12

+0

第二个选项解决了我的问题,但我需要将'localhost'更改为'127.0.0.1' – Vishrant 2018-01-28 01:24:03