无法加载JDBC驱动程序类' com.mysql.jdbc.GoogleDriver' - GAE + Java + Hibernate + Spring

时间:2014-10-21 15:08:58

标签: java mysql spring hibernate google-app-engine

我正在尝试使用Push-to-deploy with CI(构建,测试,部署)为GAE设置项目,并且无法让我的测试运行。在我当地的电脑上一切都很好。

来自谷歌日志文件:

  integrationTest(my.package.theTest): Cannot load JDBC driver class 'com.mysql.jdbc.GoogleDriver'
  integrationTest(my.package.theTest): Could not open Hibernate Session for transaction; nested exception is org.hibernate.exception.GenericJDBCException: Could not open connection

我在GAE 上运行项目的配置是:

应用服务引擎-web.xml中

<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
    <application>my-app-id</application>
    <version>${appengine.app.version}</version>
    <threadsafe>true</threadsafe>
    <use-google-connector-j>true</use-google-connector-j>
</appengine-web-app>

dataSource.properties

jdbc.driverClassName=com.mysql.jdbc.GoogleDriver
jdbc.url=jdbc:google:mysql://my-app-id:my-instance/my_table?user=user
jdbc.username=user
jdbc.password=user

dataSource.xml

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location">
        <value>classpath:db/dataSource.properties</value>
    </property>
</bean>

<bean id="dataSource"
      class="org.apache.commons.dbcp.BasicDataSource">
    <property name="driverClassName" value="${jdbc.driverClassName}"/>
    <property name="url" value="${jdbc.url}"/>
    <property name="username" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/>
</bean>

hibernate.xml

<import resource="dataSource.xml" />

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="packagesToScan" value="my.package" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
            <prop key="hibernate.show_sql">false</prop>
        </props>
    </property>
    <property name="entityInterceptor" ref="modelInterceptor" />
</bean>

<bean id="transactionManager"
    class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>

<tx:annotation-driven transaction-manager="transactionManager" />

的applicationContext.xml

<import resource="db/hibernate.xml" />

AbstractDao.java

@Transactional
@Component
public class AbstractDao<T> implements Dao<T> {

    @Autowired
    SessionFactory sessionFactory;

    @Override
    public void save(T entity) {
        getSession().save(entity);
    }

// other dao code

    private Session getSession() {
        return sessionFactory.getCurrentSession();
    }

}

根/ pom.xml的

  <packaging>pom</packaging>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <appengine.target.version>1.9.10</appengine.target.version>
  </properties>

  <build>
      <pluginManagement>
          <plugins>
              <plugin>
                  <groupId>com.google.appengine</groupId>
                  <artifactId>appengine-maven-plugin</artifactId>
                  <version>${appengine.target.version}</version>
              </plugin>
          </plugins>
      </pluginManagement>
  </build>
  <modules>
    <module>project-war</module>
    <module>project-ear</module>
  </modules>

根/项目耳/ pom.xml的

<packaging>war</packaging>

<properties>
    <buildDirectory>../target</buildDirectory>
</properties>

<parent>
    ...
</parent>

<build>
    <directory>${buildDirectory}</directory>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-ear-plugin</artifactId>
            <version>2.8</version>
            <configuration>
                <version>5</version>
                <defaultLibBundleDir>lib</defaultLibBundleDir>
                <unpackTypes>war</unpackTypes>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>

<dependencies>
    <dependency>
        <groupId>my.groupId</groupId>
        <artifactId>project-war</artifactId>
        <version>1.0-SNAPSHOT</version>
        <type>war</type>
    </dependency>
</dependencies>

强文

<modelVersion>4.0.0</modelVersion>
<packaging>war</packaging>
<artifactId>project-war</artifactId>

<parent>
    <groupId>my.groupId</groupId>
    <artifactId>root</artifactId>
    <version>1.0-SNAPSHOT</version>
</parent>

<dependencies>
    <!-- Compile/runtime dependencies -->
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-1.0-sdk</artifactId>
        <version>${appengine.target.version}</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.30</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>4.3.5.Final</version>
    </dependency>
    <dependency>
        <groupId>commons-dbcp</groupId>
        <artifactId>commons-dbcp</artifactId>
        <version>1.2.2</version>
    </dependency>

//其他依赖

<build>
    <outputDirectory>target/${project.artifactId}-${project.version}/WEB-INF/classes</outputDirectory>

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.3</version>
            <configuration>
                <archiveClasses>true</archiveClasses>
                <webResources>
                    <!-- in order to interpolate version from pom into appengine-web.xml -->
                    <resource>
                        <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                        <filtering>true</filtering>
                        <targetPath>WEB-INF</targetPath>
                    </resource>
                </webResources>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <version>2.5.1</version>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>

0 个答案:

没有答案