3

我正在开发我的项目 Spring MVC、Hibernate 和 H2 数据库。在我从 MySQL 迁移到 H2 之前,一切都在 MySQL 上运行良好。在从 MySQL 到 H2 数据库的更改之后,我有这个:

2013-07-18 15:40:01,193 DEBUG [com.mchange.v2.resourcepool.BasicResourcePool] - <acquire test -- pool size: 0; target_pool_size: 3; desired target? 1>
2013-07-18 15:40:01,193 DEBUG [com.mchange.v2.resourcepool.BasicResourcePool] - <awaitAvailable(): [unknown]>
2013-07-18 15:40:01,194 DEBUG [com.mchange.v2.resourcepool.BasicResourcePool] - <trace com.mchange.v2.resourcepool.BasicResourcePool@19f9444 [managed: 0, unused: 0, excluded: 0]>
2013-07-18 15:40:01,192 WARN [com.mchange.v2.c3p0.DriverManagerDataSource] - <Could not load driverClass org.h2.Drive>
java.lang.ClassNotFoundException: org.h2.Drive
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:186)
    at com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:100)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:132)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
    at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
2013-07-18 15:40:01,192 WARN [com.mchange.v2.c3p0.DriverManagerDataSource] - <Could not load driverClass org.h2.Drive>
java.lang.ClassNotFoundException: org.h2.Drive
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:186)
    at com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:100)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:132)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
    at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
2013-07-18 15:40:01,194 DEBUG [com.mchange.v2.resourcepool.BasicResourcePool] - <An exception occurred while acquiring a poolable resource. Will retry.>
java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getDriver(DriverManager.java:289)
    at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:223)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
    at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
2013-07-18 15:40:01,194 DEBUG [com.mchange.v2.resourcepool.BasicResourcePool] - <An exception occurred while acquiring a poolable resource. Will retry.>
java.sql.SQLException: No suitable driver
    at java.sql.DriverManager.getDriver(DriverManager.java:289)
    at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:223)
    at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
    at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
    at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
    at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
    at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
2013-07-18 15:40:01,194 DEBUG [com.mchange.v2.resourcepool.BasicResourcePool] - <An exception occurred while acquiring a poolable resource. Will retry.>

似乎它无法从任何地方加载 H2 数据库驱动程序,我将它放在我的类路径中,甚至两次我从 Maven 加载它并手动作为常用库加载它。我还检查了我的数据源两次,一切都是正确的。

我的应用程序配置:

        <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <!-- Using and configuring C3P0 proxy -->
        <property name="driverClass"><value>org.h2.Drive</value></property>
        <property name="jdbcUrl"><value>jdbc:h2:/home/vadim/workspace-sts/h2/EDUCATION</value></property>
        <property name="user"><value>sa</value></property>
        <property name="password"><value></value></property>
        <property name="initialPoolSize"><value>3</value></property> <!-- Number of Connections a pool will try to acquire upon startup -->
        <property name="minPoolSize"><value>1</value></property> <!-- Minimum connection pool size -->
        <property name="maxPoolSize"><value>20</value></property> <!-- Max connection pool size -->
        <property name="maxConnectionAge"><value>3600</value></property> <!-- Set max connection age to 1 hour, after it will release -->
        <property name="maxIdleTime"><value>600</value></property> <!-- 10 minutes connection can stay unused before be discarded -->
        <property name="checkoutTimeout"><value>240000</value></property> <!-- Each what time check for unused connections -->
        </bean>

    <!-- Declare Hibernate transaction manager. Realization of PlatformTransactionManager-->
    <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
        <property name="sessionFactory" ref ="sessionFactory"/>
    </bean>

    <tx:advice  id="txAdvice" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="fetch*" propagation="REQUIRED" read-only="true" />
            <tx:method name="*"/>
        </tx:attributes>    
    </tx:advice>

    <aop:config>
        <aop:pointcut id="eduWebPointcuts" expression="execution(* edu.demidov.service.EducationWebServiceImpl.*(..))"/>
        <aop:advisor advice-ref="txAdvice" pointcut-ref="eduWebPointcuts"/> 
    </aop:config>

    <!-- Looks for specific annotation configuration in this packages -->
    <context:component-scan base-package="edu.demidov.dao, edu.demidov.service"/>

    <!-- Declare annotation configuration -->
    <context:annotation-config />

    <!-- Build sessionFactory annotation base configuration -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">

        <property name="dataSource" ref ="dataSource"/> <!-- Injecting datasource C3P0 to Hibernate sessionFactory datasource -->
        <property name="packagesToScan" value="edu.demidov.dto"/> <!-- Package will be scanned for entity classes -->

        <property name="hibernateProperties">   <!-- Configuring properties -->
            <props> 

                <prop key="hibernate.dialect"> org.hibernate.dialect.H2Dialect</prop> <!-- Put dialect for particular database to use queries to this DB -->
                <prop key="show_sql">true</prop>


                <prop key="hibernate.c3p0.min_size">1</prop> <!-- Same to minPoolSize -->
                <prop key="hibernate.c3p0.max_size">20</prop> <!--Same to maxPoolSize -->
                <prop key="hibernate.c3p0.timeout">600</prop> <!-- Same to maxIdleTime -->
                <prop key="hibernate.c3p0.max_statements">5</prop> <!-- Set number of cached statements used often -->

                <prop key="hibernate.max_fetch_depth">3</prop>  <!-- Sets a maximum "depth" for the outer join fetch tree for single-ended associations (one-to-one, many-to-one) -->
                <prop key="hibernate.jdbc.fetch_size">30</prop> <!-- Declare how many records will get from database in one package -->
                <prop key="hibernate.jdbc.batch_size">15</prop> <!-- When it's a lot of queries in short time passed to database this put queries in one batch and send them to database -->
                <prop key="hibernate.show_sql">true</prop>

            </props>
       </property> <!-- End of configuration hibernateProperties -->

    </bean> <!-- End of configuring org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean -->


</beans>

我的 web.xml

<context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/spring/root-context.xml
           /WEB-INF/spring/app-Confing.xml
        </param-value>
    </context-param>

    <!-- Creates the Spring Container shared by all Servlets and Filters -->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <!-- Processes application requests -->
    <servlet>
        <servlet-name>appServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>appServlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>
4

1 回答 1

5

打错了,试试org.h2.Driver

于 2013-07-13T16:17:49.630 回答