org.apache.http.client.HttpResponseException:未提供身份验证标头

时间:2016-11-08 10:02:56

标签: spring-boot neo4j spring-data-neo4j spring-data-neo4j-4

我正在使用Spring Boot配置neo4j数据库。我能够设置Spring Boot,它运行正常。但是当我配置neo4j时,它会抛出异常org.apache.http.client.HttpResponseException: No authentication header supplied

日志存储如下:

2016-11-08 15:20:54.962  INFO 4932 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : FrameworkServlet 'dispatcherServlet': initialization completed in 23 ms
2016-11-08 15:24:29.062  INFO 4932 --- [nio-8080-exec-2] o.n.o.drivers.http.request.HttpRequest   : Thread: 27, url: http://localhost:7474/db/data/transaction/commit, request: {"statements":[{"statement":"MATCH (user:User) WHERE user.id = {id} RETURN user","parameters":{"id":"10"},"resultDataContents":["graph"],"includeStats":false}]}
2016-11-08 15:24:29.285  WARN 4932 --- [nio-8080-exec-2] o.n.o.drivers.http.request.HttpRequest   : Thread: 27, response: No authentication header supplied.
2016-11-08 15:24:29.288  INFO 4932 --- [nio-8080-exec-2] o.s.d.neo4j.config.Neo4jConfiguration    : Intercepted exception
2016-11-08 15:24:29.299 ERROR 4932 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.neo4j.ogm.drivers.http.request.HttpRequestException: http://localhost:7474/db/data/transaction/commit: No authentication header supplied.] with root cause

org.apache.http.client.HttpResponseException: No authentication header supplied.
    at org.neo4j.ogm.drivers.http.request.HttpRequest.execute(HttpRequest.java:203) ~[neo4j-ogm-http-driver-2.0.5.jar:na]
    at org.neo4j.ogm.drivers.http.request.HttpRequest.executeRequest(HttpRequest.java:168) ~[neo4j-ogm-http-driver-2.0.5.jar:na]
    at org.neo4j.ogm.drivers.http.request.HttpRequest.execute(HttpRequest.java:87) ~[neo4j-ogm-http-driver-2.0.5.jar:na]
    at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.executeAndMap(ExecuteQueriesDelegate.java:114) ~[neo4j-ogm-core-2.0.5.jar:na]
    at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.query(ExecuteQueriesDelegate.java:87) ~[neo4j-ogm-core-2.0.5.jar:na]
    at org.neo4j.ogm.session.delegates.ExecuteQueriesDelegate.queryForObject(ExecuteQueriesDelegate.java:61) ~[neo4j-ogm-core-2.0.5.jar:na]
    at org.neo4j.ogm.session.Neo4jSession.queryForObject(Neo4jSession.java:363) ~[neo4j-ogm-core-2.0.5.jar:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_31]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_31]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_31]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_31]
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:333) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at com.sun.proxy.$Proxy60.queryForObject(Unknown Source) ~[na:na]

配置类:

public class ApplicationConfiguration extends Neo4jConfiguration{

    @Bean
    public Configuration getConfiguration(){
        Configuration config = new Configuration();
        config.driverConfiguration()
            .setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver")
            .setURI("http://neo4j:welcome*123@localhost:7474");
        return config;
    }

    @Bean
    public SessionFactory getSessionFactory(){
        return new SessionFactory(getConfiguration(), "com.ent.entity");
    }

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

2 个答案:

答案 0 :(得分:0)

Spring Boot具有配置属性列表,可以在" application.properties"中设置。文件。

设置这些可能会解决问题:

spring.data.neo4j.username=neo4j (default user)    
spring.data.neo4j.password=neo4j (default password)

答案 1 :(得分:0)

这需要在标头中进行身份验证,或者您可以禁用身份验证尝试编辑neo4j.conf install dir bin / neo4j.conf 并取消注释这一行

# Whether requests to Neo4j are authenticated.
# To disable authentication, uncomment this line
dbms.security.auth_enabled=false    

或启用neo DBMS连接器

# HTTP Connector. There must be exactly one HTTP connector.
dbms.connector.http.enabled=true
#dbms.connector.http.listen_address=:7474