亚马逊 aws ubuntu java mysql webservice“调用驱动程序时出错#connect”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22647598/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
amazon aws ubuntu java mysql webservice "Error calling Driver#connect"
提问by jon
we have some web services running on tomcat 7 / java7 / hibernate / mysql5. Everything is running perfectly on localhost tomcat server on my pc but when we deploy the application on the AWS Ubuntu server, we get this error message:
我们有一些 web 服务在 tomcat 7 / java7 / hibernate / mysql5 上运行。一切都在我电脑上的 localhost tomcat 服务器上完美运行,但是当我们在 AWS Ubuntu 服务器上部署应用程序时,我们收到以下错误消息:
Mar 25, 2014 9:59:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!) Mar 25, 2014 9:59:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://ec2-54-197-214-209.compute-1.amazonaws.com:3306/ChronoMetriq] Mar 25, 2014 9:59:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH000046: Connection properties: {user=root, password=**} Mar 25, 2014 9:59:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH000006: Autocommit mode: false Mar 25, 2014 9:59:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000115: Hibernate connection pool size: 10 (min=1) Error Creating SessionFactory: **Error calling Driver#connectnull Mar 25, 2014 9:59:52 PM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException SEVERE: The RuntimeException could not be mapped to a response, re-throwing to the HTTP container java.lang.NullPointerExceptionat ca.chronometriq.webterm.restapi.Process.getQueueName(Process.java:132) 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:606) at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60) at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185) at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288) at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469) at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699) at javax.servlet.http.HttpServlet.service(HttpServlet.java:728) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1024) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1686) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744)
2014 年 3 月 25 日 9:59:52 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl 配置警告:HHH000402:使用 Hibernate 内置连接池(不用于生产!)2014 年 3 月 25 日 9:59:下午 52 点 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO:HHH000401:在 URL [jdbc:mysql://ec2-54-197-214-209 使用驱动程序 [com.mysql.jdbc.Driver]。 compute-1.amazonaws.com:3306/ChronoMetriq] 2014 年 3 月 25 日晚上 9:59:52 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO:HHH000046:连接属性:{user=root, password=**} 2014 年 3 月 25 日晚上 9:59:52 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator INFO: HHH000006: Autocommit mode: false Mar 25, 2014 9:59:52 PM org.hibernate.engine .jdbc.connections.internal.DriverManagerConnectionProviderImpl configure INFO: HHH000115: Hibernate connection pool size: 10 (min=1) Error Creating SessionFactory: **Error call Driver#connectnull Mar 25, 2014 9:59:52 PM com.sun。 jersey.spi.container.ContainerResponse mapMappableContainerException 严重:RuntimeException 无法映射到响应,重新抛出到 HTTP 容器 java.lang.NullPointerException在 ca.chronometriq.webterm.restapi.Process.getQueueName(Process.java:132) 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:606) at com.sun.jersey.spi.container.JavaMethodInvokerFactory$1.invoke(JavaMethodInvokerFactory.java:60)在 com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$TypeOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:185) 在 com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatch( ResourceJavaMethodDispatcher.java:75) 在 com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288) 在 com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java: 147) 在 com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) 在 com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java: 147) 在 com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) 在 com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)在 com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400) 在 com.sun.jersey.server.impl.application.WebApplicationImpl。handleRequest(WebApplicationImpl.java:1349) at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339) at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent. java:416) 在 com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537) 在 com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)在 javax.servlet.http.HttpServlet.service(HttpServlet.java:728) 在 org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305) 在 org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain .java:210) 在 org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222) 在 org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123) 在 org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) 在 org.apache.catalina.core.StandardHostValve .invoke(StandardHostValve.java:171) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) at org. apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) at org.apache.coyote.http11.AbstractHttp11Processor.process(ProcessAbstract.Http11) java:1024) 在 org.apache.coyote.AbstractProtocol$AbstractConnectionHandler。process(AbstractProtocol.java:589) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1686) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java .util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 在 java.lang.Thread.run(Thread.java:744)
Here is my hibernate.cfg.xml file content:
这是我的 hibernate.cfg.xml 文件内容:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd" >
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://myaddress.compute-1.amazonaws.com:3306/ChronoMetriq</property>
<property name="hibernate.connection.release_mode">auto</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">********</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="dialect">org.hibernate.dialect.MySQL5InnoDBDialect</property>
<property name="show_sql">true</property>
<mapping class="ca.chronometriq.webterm.model.Clinic" />
...
</session-factory>
</hibernate-configuration>
And here is our session factory code:
这是我们的会话工厂代码:
public class DataObjectFactory {
@SuppressWarnings({ "rawtypes" })
private static final ThreadLocal threadLocal = new ThreadLocal();
private static ServiceRegistry serviceRegistry;
private static SessionFactory sessionFactory;
private static Configuration configuration;
private static final Logger logger = Logger.getLogger(DataAccessInterface.class.getName());
static {
try {
configuration = new Configuration().addResource("hibernate.cfg.xml");
configuration.configure();
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
} catch (Exception e) {
System.err.println("Failed to create sessionFactory object." + e);
}
}
private DataObjectFactory(){
}
@SuppressWarnings("unchecked")
public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get();
if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) ? sessionFactory.openSession() : null;
threadLocal.set(session);
}
return session;
}
public static void rebuildSessionFactory() {
try {
configuration = new Configuration().addResource("hibernate.cfg.xml");
configuration.configure();
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
} catch (HibernateException e) {
System.err.println("Error Creating SessionFactory: " + e.getMessage());
}
}
@SuppressWarnings("unchecked")
public static void closeSession() throws HibernateException {
Session session = (Session) threadLocal.get();
threadLocal.set(null);
if (session != null) {
session.flush();
session.close();
}
}
public static SessionFactory getSessionFactory() {
configuration = new Configuration().addResource("hibernate.cfg.xml");
configuration.configure();
serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
return sessionFactory;
}
public static Configuration getConfiguration() {
return configuration;
}
public static void closeRegistry() throws Exception{
if(serviceRegistry!= null) {
StandardServiceRegistryBuilder.destroy(serviceRegistry);
}
}
}
Any idea why this happens?
知道为什么会这样吗?
采纳答案by Max Methot
'Error calling Driver#connect' is normally an error you get when Tomcat isn't able to reach you database. It may be because you provided the wrong username/password combination or because your database (or Amazon in that case) might be blocking the connection from the source IP.
“调用 Driver#connect 时出错”通常是当 Tomcat 无法访问您的数据库时出现的错误。这可能是因为您提供了错误的用户名/密码组合,或者因为您的数据库(或亚马逊)可能阻止了来自源 IP 的连接。
I recommend you find the source IP and port from where you make the requests and add it to the user privileges in mysql. Grant all privileges for the 'root' user with the IP.
我建议您找到发出请求的源 IP 和端口,并将其添加到 mysql 中的用户权限中。授予具有 IP 的“root”用户的所有权限。
You can do so by calling:
您可以通过调用:
GRANT ALL PRIVILEGES ON .TO 'root'@'x.x.x.x' IDENTIFIED BY 'the_password' WITH GRANT OPTION;
授予所有特权。TO 'root'@'xxxx' 由 'the_password' 识别,并带有 GRANT 选项;
where x.x.x.x is the source IP (if mysql and tomcat are on the same server, and it's an Amazon EC2 instance, make sure to execute that query with the private ip of your EC2 instance as well as the private DNS, like ip-x-x-x-x.ec2.internal).
其中 xxxx 是源 IP(如果 mysql 和 tomcat 在同一台服务器上,并且它是 Amazon EC2 实例,请确保使用您的 EC2 实例的私有 ip 以及私有 DNS 执行该查询,例如 ip-xxxx。 ec2.internal)。
In the end, the granted users in your MySQL database should be 'root' from hosts: 127.0.0.1 / localhost / ::1 / your EC2 private IP / your EC2 private DNS (and other external IPs if you plan on calling it from outside the localhost).
最后,您的 MySQL 数据库中授予的用户应该是来自主机的“root”:127.0.0.1 / localhost / ::1 / 您的 EC2 私有 IP / 您的 EC2 私有 DNS(以及其他外部 IP,如果您计划从在本地主机之外)。
Hope it helps. Max
希望能帮助到你。最大限度