无法加载JDBC驱动程序类'com.mysql.jdbc.GoogleDriver' [英] Cannot load JDBC driver class 'com.mysql.jdbc.GoogleDriver'

查看:1897
本文介绍了无法加载JDBC驱动程序类'com.mysql.jdbc.GoogleDriver'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我面临一个非常奇怪的问题,那就是我的App Engine服务器无法加载其Cloud SQL的GoogleDriver,这是错误(运行mvn appengine:update后就会发生)。

  org.springframework.transaction.CannotCreateTransactionException:无法为事务打开Hibernate Session;嵌套异常是org.hibernate.exception.GenericJDBCException:无法打开连接
在org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:596)
...
引起:org.apache.commons.dbcp.SQLNestedException:无法在org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1429)$ b加载JDBC驱动程序类'com.mysql.jdbc.GoogleDriver'
$ b在org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
在org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
在org .springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
... 48 more
由:java.lang.ClassNotFoundException引起:com.mysql.jdbc.GoogleDriver

appengine.properties

  ################### MySQL配置 -  Google Cloud App Engine ################## ######## 
jdbc.driverClassName = com.mysql.jdbc.GoogleDriver
jdbc.url = jdbc:google:mysql:// mytestapp:testdb?user = someuser
jdbc.username = someuser
jdbc.password = ******
jdbc.dialect = org.hibernate.dialect.MySQLDialect

在我的Spring上下文中,我有:

 < context:property -placeholder location =classpath:appengine.properties/> 
< bean
id =dataSource
class =org.apache.commons.dbcp.BasicDataSource
destroy-method =close>

name =driverClassName
value =$ {jdbc.driverClassName}/>
name =url
value =$ {jdbc.url}/>
...

有什么想法?

==



为了确认,我已经配置了我的appengine-web.xml,它根本没有帮助:

 <?xml version =1.0encoding =utf-8?> 
< appengine-web-app xmlns =http://appengine.google.com/ns/1.0>
< application> mytestapp< / application>
< version> 1< / version>
< threadsafe> true< / threadsafe>
<会话启用>真实< /会话启用>

< system-properties>
< property name =java.util.logging.config.filevalue =WEB-INF / logging.properties/>
< / system-properties>

< use-google-connector-j> true< / use-google-connector-j>
< / appengine-web-app>

-



我无法由于hibernate jar版本之间存在一些不兼容问题,所以我继续尝试通过实际版本管道(Jenkins + Maven + build + test + deploy),我不得不将Compute Engine虚拟机的IP地址添加到云授权IP列表中SQL实例为了运行我的单元测试并将其部署到应用程序(但是,如果我保持这种方法,我只能使用MySQL驱动程序和URL而不是GoogleDriver和URL,所以这变得棘手......)。



我在由我的Spring MVC配置文件加载的Production.properties文件中拥有这些属性:

  ################### MySQL配置 -  Google Cloud App Engine ############### ########### 
jdbc.driverClassName = com.mysql.jdbc.GoogleDriver
jdbc.url = jdbc:google:mysql:// ******* testapp :testsqldb?user = root
jdbc.username = root
jdbc.password = *****
jdbc.dialect = org.hibernate.dialect.MySQL方言

是否有一种简单的方法可以在不使用此方法的情况下动态切换外部和GAE Cloud SQL连接详细信息?

  if(SystemProperty.environment.value()== 
SystemProperty.Environment.Value.Production){
//从App Engine连接。

有什么想法?

解决方案



编辑添加(来自以下评论):




I am facing a very bizarre problem where my App Engine server can't load its Cloud SQL's GoogleDriver, here's the error (It happens right after I run "mvn appengine:update").

org.springframework.transaction.CannotCreateTransactionException: Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Cannot open connection
        at org.springframework.orm.hibernate3.HibernateTransactionManager.doBegin(HibernateTransactionManager.java:596)
        ...
Caused by: org.apache.commons.dbcp.SQLNestedException: Cannot load JDBC driver class 'com.mysql.jdbc.GoogleDriver'
        at org.apache.commons.dbcp.BasicDataSource.createConnectionFactory(BasicDataSource.java:1429)
        at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:1371)
        at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:1044)
        at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:81)
        at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
        ... 48 more
Caused by: java.lang.ClassNotFoundException: com.mysql.jdbc.GoogleDriver

appengine.properties

################### MySQL Configuration - Google Cloud App Engine ##########################
jdbc.driverClassName=com.mysql.jdbc.GoogleDriver
jdbc.url=jdbc:google:mysql://mytestapp:testdb?user=someuser
jdbc.username=someuser
jdbc.password=******
jdbc.dialect=org.hibernate.dialect.MySQLDialect

In my Spring context file I have:

<context:property-placeholder location="classpath:appengine.properties" />
<bean
    id="dataSource"
    class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close" >

    <property
        name="driverClassName"
        value="${jdbc.driverClassName}" />
    <property
        name="url"
        value="${jdbc.url}" />
    ...

Any ideas?

==

Just to confirm, I had already configured my appengine-web.xml and it doesn't help at all:

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
    <application>mytestapp</application>
    <version>1</version>
    <threadsafe>true</threadsafe>
    <sessions-enabled>true</sessions-enabled>

    <system-properties>
        <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
    </system-properties>

    <use-google-connector-j>true</use-google-connector-j>
</appengine-web-app>

--

I couldn't move forward due to some incompatibility between hibernate jar versions so I kept trying through the actual release pipeline (Jenkins + Maven + build + test + deploy), I had to add the Compute Engine VM's IP address to the list of authorized IPs of the Cloud SQL Instance in order to run my unit tests and deploy it to the application (but, if I keep this approach, I can only use the MySQL driver and URL instead of the GoogleDriver and URL. So this is getting tricky...).

I have these properties in a Production.properties file that is loaded by my Spring MVC config file:

################### MySQL Configuration - Google Cloud App Engine ##########################
jdbc.driverClassName=com.mysql.jdbc.GoogleDriver
jdbc.url=jdbc:google:mysql://*******testapp:testsqldb?user=root
jdbc.username=root
jdbc.password=*****
jdbc.dialect=org.hibernate.dialect.MySQLDialect

Is there an easy way to dynamically switch between external and GAE Cloud SQL connection details without using this approach?

if (SystemProperty.environment.value() ==
SystemProperty.Environment.Value.Production) {
    // Connecting from App Engine.

Any ideas?

解决方案

Edited to add (from comments below):

  • Also, when connecting to Cloud SQL from GAE you should leave the password field empty.
  • You should also make sure that if your code is running outside GAE (e.g. on your workstation, on GCE, on a Jenkins build) it uses stock MySQL connector as the Google connector is only available on GAE.
  • You might also want too look into using the stock MySQL driver, which works both from GAE and other connections. There is a demo of this at https://github.com/GoogleCloudPlatform/appengine-cloudsql-native-mysql-hibernate-jpa-demo-java

这篇关于无法加载JDBC驱动程序类'com.mysql.jdbc.GoogleDriver'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆