问题描述
我正在使用正确的 NEO4J_URL
环境变量,如 heroku config
所示。
如果我通过浏览器使用相同的neo4j url,它可以正常工作(没有认证失败)。但是,我的应用程序无法从heroku下面的错误开始。 (我正在使用spring-data-neo4j)
该URL看起来像 http:// username:[email protected] :1234 /分贝/数据/
。在最后没有'/ db / data'的时候试过,也没有结尾的斜杠。没有帮助。
如果有人已经遇到/解决了这个问题,请帮忙。服务器启动时的堆栈跟踪:
←[36m2013-03-06T23:44:31 + 00:00 app [web。 1]:←[0m引起:
←[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:读取为JSON时出错'< ; html> |< head> |< meta http-equiv =Content-Typecontent =text / html; charset = ISO-8859-1/> |< tit
le> Error 401 UNAUTHORIZED< / head> |< body>< h2> HTTP ERROR 401< / h2> |< p>访问/ db / data / index / node时出现问题。原因是:|<预> UNAUTHORIZED< / pre>< / p>< i>< i><小>由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>)
←[36 m2013-03-06T23:44:31 + 00:00 app [web.1]:←[0m at org.springframework.data.neo4j.rest.SpringRestGraphDatabase.getIndex(SpringRestGraphDatabase.java:100
解决方案如@MichaelHunger所示,我使用了其他
SpringRestGraphDatabase
将用户名和密码作为单独参数的构造函数,现在可以访问neo数据库。
我之前的spring上下文看起来像这样
< bean id =graphDatabaseServiceclass =org.springframework.data.neo4j.rest.SpringRestGraphDatabase>
< constructor-arg index =0value =$ {NEO4J_URL}/>
< / bean>
现在我将它改为如下所示,一切正常!在这里我通过两个额外的环境变量提供用户名和密码。是的,在设置heroku上的用户名和密码环境变量方面有一些小小的手动工作(或者更不用说,您可以在应用程序中硬编码)。这是在添加neo4j heroku插件后自动可用的NEO4J_URL环境变量的补充。
< bean id =graphDatabaseServiceclass =org.springframework.data.neo4j.rest.SpringRestGraphDatabase>
< constructor-arg index =0value =$ {NEO4J_URL}/>
< constructor-arg index =1value =$ {NEO4J_USERNAME}/>
< constructor-arg index =2value =$ {NEO4J_PASSWORD}/>
< / bean>
感谢@MichaelHunger!
I am using correct
NEO4J_URL
environment variable as shown inheroku config
. If I use the same neo4j url via a browser, it works fine (no auth failure). However my application fails to start with below error on heroku. (I am using spring-data-neo4j)The URL looks like
http://username:[email protected]:1234/db/data/
. Tried without '/db/data' at the end and also with and without trailing slash. Didn't help.Please help if anyone has already faced/resolved this issue. The stack trace on server startup:
←[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
解决方案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!
这篇关于在Heroku上为Neo4j REST网址'错误401未经授权'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!