我在AWS上设置了MongoDB实例,并尝试从安装了我的Web应用程序的另一个AWS实例连接到它。
以下是我的jdoconfig.xml文件的内容:
<jdoconfig xmlns="http://java.sun.com/xml/ns/jdo/jdoconfig"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://java.sun.com/xml/ns/jdo/jdoconfig http://java.sun.com/xml/ns/jdo/jdoconfig_3_0.xsd">
<persistence-manager-factory name="MY-PMF">
<property name="javax.jdo.PersistenceManagerFactoryClass"
value="org.datanucleus.api.jdo.JDOPersistenceManagerFactory" />
<property name="javax.jdo.option.ConnectionURL" value="mongodb://ec2-[...].eu-west-1.compute.amazonaws.com:27017/mydb" />
<property name="javax.jdo.option.Mapping" value="mongodb" />
<property name="javax.jdo.option.ConnectionUserName" value="myuser" />
<property name="javax.jdo.option.ConnectionPassword" value="mypassword" />
<property name="javax.jdo.option.Optimistic" value="false" />
<property name="datanucleus.autoCreateSchema" value="true" />
</persistence-manager-factory>
</jdoconfig>
但是,Web应用程序无法连接到MongoDB实例。以下是来自日志的错误消息:
com.mongodb.MongoException$Network: can't call something : localhost/127.0.0.1:27017//ec2-[...].eu-west-1.compute.amazonaws.com:27017/mydb
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:226)
at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:313)
at com.mongodb.DB.command(DB.java:174)
at com.mongodb.DB.command(DB.java:158)
at com.mongodb.DB.command(DB.java:198)
at com.mongodb.DB.command(DB.java:144)
at com.mongodb.DB._doauth(DB.java:555)
at com.mongodb.DB.authenticate(DB.java:492)
at org.datanucleus.store.mongodb.ConnectionFactoryImpl$ManagedConnectionImpl.getConnection(ConnectionFactoryImpl.java:200)
at org.datanucleus.store.mongodb.MongoDBStoreManager.addClasses(MongoDBStoreManager.java:127)
at org.datanucleus.store.AbstractStoreManager.addClass(AbstractStoreManager.java:1137)
at org.datanucleus.ObjectManagerImpl.newObjectId(ObjectManagerImpl.java:3310)
at org.datanucleus.api.jdo.JDOPersistenceManager.newObjectIdInstance(JDOPersistenceManager.java:1627)
at org.datanucleus.api.jdo.JDOPersistenceManager.getObjectById(JDOPersistenceManager.java:1749)
at com.myapp.server.auth.MyActionHandler.execute(MyActionHandler.java:67)
at com.myapp.server.auth.MyActionHandler.execute(MyActionHandler.java:1)
at com.gwtplatform.dispatch.server.AbstractDispatchImpl.doExecute(AbstractDispatchImpl.java:153)
at com.gwtplatform.dispatch.server.AbstractDispatchImpl.execute(AbstractDispatchImpl.java:111)
at com.gwtplatform.dispatch.server.AbstractDispatchServiceImpl.execute(AbstractDispatchServiceImpl.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:561)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at com.google.inject.servlet.ServletDefinition.doService(ServletDefinition.java:263)
at com.google.inject.servlet.ServletDefinition.service(ServletDefinition.java:178)
at com.google.inject.servlet.ManagedServletPipeline.service(ManagedServletPipeline.java:91)
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:62)
at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:168)
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58)
at com.google.inject.servlet.FilterDefinition.doFilter(FilterDefinition.java:168)
at com.google.inject.servlet.FilterChainInvocation.doFilter(FilterChainInvocation.java:58)
at com.google.inject.servlet.ManagedFilterPipeline.dispatch(ManagedFilterPipeline.java:118)
at com.google.inject.servlet.GuiceFilter.doFilter(GuiceFilter.java:113)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.RemoteIpValve.invoke(RemoteIpValve.java:680)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:928)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:987)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:539)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:300)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
Caused by: java.io.IOException: couldn't connect to [localhost/127.0.0.1:27017] bc:java.net.ConnectException: Connection refused
at com.mongodb.DBPort._open(DBPort.java:222)
at com.mongodb.DBPort.go(DBPort.java:111)
at com.mongodb.DBPort.call(DBPort.java:78)
at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:217)
... 55 more
看起来ConnectionURL不正确; DataNucleus JDO实现正在尝试连接到localhost,而不是我的数据库所在的实例。
任何人都可以告诉我正确的ConnectionURL应该是什么样子,或者你认为问题在别处指向我吗?
答案 0 :(得分:2)
你的意思是你没有正确指定connectionURL,按照 http://www.datanucleus.org/products/accessplatform_3_1/mongodb/support.html
我希望更像“mongodb:servername:/ mydb”......根据文档