1

我正在使用正确的NEO4J_URL环境变量,如heroku config. 如果我通过浏览器使用相同的 neo4j url,它可以正常工作(没有身份验证失败)。但是,我的应用程序无法以 heroku 上的以下错误开始。(我正在使用 spring-data-neo4j)

URL 看起来像http://username:password@123456ac6.hosted.neo4j.org:1234/db/data/. 尝试在末尾不使用“/db/data”,也尝试使用和不使用斜杠。没有帮助。

如果有人已经遇到/解决了这个问题,请提供帮助。服务器启动时的堆栈跟踪:

←[36m2013-03-06T23:44:31+00:00 app[web.1]:←[0m Caused by:
←[36m2013-03-06T23:44:31+00:00 app[web.1]:←[0m  at org.neo4j.rest.graphdb.index.RestIndexManager.existsForNodes(RestIndexManager.java:45)
←[36m2013-03-06T23:44:31+00:00 app[web.1]:←[0m java.lang.RuntimeException: Error reading as JSON '<html>|<head>|<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>|<tit
le>Error 401 UNAUTHORIZED</title>|</head>|<body><h2>HTTP ERROR 401</h2>|<p>Problem accessing /db/data/index/node. Reason:|<pre>    UNAUTHORIZED</pre></p><hr /><i><small>Powered by Jetty://</
small></i><br/>                                                |<br/>                                                |<br/>                                                |<br/>
                                   |<br/>                                                |<br/>                                                |<br/>
       |<br/>                                                |<br/>                                                |<br/>                                                |<br/>
                                 |<br/>                                                |<br/>
←[36m2013-03-06T23:44:31+00:00 app[web.1]:←[0m  at org.neo4j.rest.graphdb.util.JsonHelper.jsonToSingleValue(JsonHelper.java:62)
←[36m2013-03-06T23:44:31+00:00 app[web.1]:←[0m  at org.neo4j.rest.graphdb.RequestResult.toEntity(RequestResult.java:114)
←[36m2013-03-06T23:44:31+00:00 app[web.1]:←[0m                      |<br/>                                                |<br/>                                                |<br/>
                                        |<br/>                                                |<br/>                                                |<br/>
            |<br/>                                                ||</body>|</html>|'
←[36m2013-03-06T23:44:31+00:00 app[web.1]:←[0m  at org.neo4j.rest.graphdb.RequestResult.toMap(RequestResult.java:120)
←[36m2013-03-06T23:44:31+00:00 app[web.1]:←[0m  at org.neo4j.rest.graphdb.util.JsonHelper.readJson(JsonHelper.java:57)
←[36m2013-03-06T23:44:31+00:00 app[web.1]:←[0m  at org.neo4j.rest.graphdb.index.RestIndexManager.indexInfo(RestIndexManager.java:50)
←[36m2013-03-06T23:44:31+00:00 app[web.1]:←[0m  at org.springframework.data.neo4j.support.typerepresentation.TypeRepresentationStrategyFactory.chooseStrategy(TypeRepresentationStrategyFactor
y.java:56)
←[36m2013-03-06T23:44:31+00:00 app[web.1]:←[0m  at org.neo4j.rest.graphdb.ExecutingRestAPI.indexInfo(ExecutingRestAPI.java:327)
←[36m2013-03-06T23:44:31+00:00 app[web.1]:←[0m  at org.springframework.data.neo4j.config.Neo4jConfiguration$$EnhancerByCGLIB$$36bc2a37.CGLIB$typeRepresentationStrategyFactory$7(<generated>)
←[36m2013-03-06T23:44:31+00:00 app[web.1]:←[0m  at org.springframework.data.neo4j.rest.SpringRestGraphDatabase.getIndex(SpringRestGraphDatabase.java:100
4

1 回答 1

1

As suggested by @MichaelHunger I used other SpringRestGraphDatabase Constructor which takes username and password as separate parameters, now the neo database is accessible.

My earlier spring context looked like this

<bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
    <constructor-arg index="0" value="${NEO4J_URL}" />
</bean>

Now I changed it to as below and everything works fine! Here I provide the username and password via two additional environment variables. Yes, there is a little manual work in terms of setting username and password environment variables on heroku(or less preferably, you can hard code the same in your application). This is in addition to the NEO4J_URL environment variable automatically available after adding neo4j heroku add-on.

<bean id="graphDatabaseService" class="org.springframework.data.neo4j.rest.SpringRestGraphDatabase">
    <constructor-arg index="0" value="${NEO4J_URL}" />
    <constructor-arg index="1" value="${NEO4J_USERNAME}" />
    <constructor-arg index="2" value="${NEO4J_PASSWORD}" />
</bean>

Thanks @MichaelHunger!

于 2013-03-11T04:42:05.707 回答