2011-12-12 39 views
0

我正在使用Spring 3.0.5,MSSQLServer 2008(使用JTDS)Tomcat 7.0.23。我想從普通的DBCP移開,並試圖在我的應用程序-config.xml文件以下在CCE中配置Tomcat 7 JDBC Pool with Spring結果

<bean id="ipeDS" class="org.apache.tomcat.jdbc.pool.DataSource" 
    p:driverClassName="net.sourceforge.jtds.jdbcx.JtdsDataSource" 
    p:url="${url}" 
    p:username="${username}" 
    p:password="${password}" 
    p:initialSize="${initial.size}" 
    p:maxActive="${max.active}" 
    p:jdbcInterceptors="org.apache.tomcat.jdbc.pool.interceptor.ConnectionState;org.apache.tomcat.jdbc.pool.interceptor.StatementFinalizer"/> 

這導致

Caused by: java.lang.ClassCastException: net.sourceforge.jtds.jdbcx.JtdsDataSource cannot be cast to java.sql.Driver

完整的堆棧跟蹤:

java.sql.SQLException: net.sourceforge.jtds.jdbcx.JtdsDataSource cannot be cast to java.sql.Driver 
at org.apache.tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:243) 
at org.apache.tomcat.jdbc.pool.PooledConnection.connect(PooledConnection.java:176) 
at org.apache.tomcat.jdbc.pool.ConnectionPool.createConnection(ConnectionPool.java:662) 
at org.apache.tomcat.jdbc.pool.ConnectionPool.borrowConnection(ConnectionPool.java:602) 
at org.apache.tomcat.jdbc.pool.ConnectionPool.init(ConnectionPool.java:465) 
at org.apache.tomcat.jdbc.pool.ConnectionPool.<init>(ConnectionPool.java:130) 
at org.apache.tomcat.jdbc.pool.DataSourceProxy.pCreatePool(DataSourceProxy.java:112) 
at org.apache.tomcat.jdbc.pool.DataSourceProxy.createPool(DataSourceProxy.java:99) 
at org.apache.tomcat.jdbc.pool.DataSourceProxy.getConnection(DataSourceProxy.java:123) 
at org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider.getConnection(InjectedDataSourceConnectionProvider.java:71) 
at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:51) 
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:168) 
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:375) 
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1842) 
at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:902) 
at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:74) 
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225) 
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:398) 
at org.springframework.beans.factory.BeanFactoryUtils.beansOfTypeIncludingAncestors(BeanFactoryUtils.java:275) 
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.detectPersistenceExceptionTranslators(PersistenceExceptionTranslationInterceptor.java:139) 
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.<init>(PersistenceExceptionTranslationInterceptor.java:79) 
at org.springframework.dao.annotation.PersistenceExceptionTranslationAdvisor.<init>(PersistenceExceptionTranslationAdvisor.java:70) 
at org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor.setBeanFactory(PersistenceExceptionTranslationPostProcessor.java:99) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeAwareMethods(AbstractAutowireCapableBeanFactory.java:1439) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1408) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) 
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) 
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) 
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) 
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) 
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194) 
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors(AbstractApplicationContext.java:710) 
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:410) 
at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:276) 
at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197) 
at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) 
at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4765) 
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5260) 
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1525) 
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1515) 
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303) 
at java.util.concurrent.FutureTask.run(FutureTask.java:138) 
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) 
at java.lang.Thread.run(Thread.java:662) 

導致:java.lang.ClassCastException:net.sourceforge.jtds.jdbcx.JtdsDataSource無法轉換爲java.sql.Driver at org.apache .tomcat.jdbc.pool.PooledConnection.connectUsingDriver(PooledConnection.java:236) ... 54更多

任何指針將不勝感激。 謝謝。

回答

0

在我看來像org.apache.tomcat.jdbc.pool.DataSource不是兼容的數據源?

我在使用c3p0之前使用JDTS配置了一個數據源。繼承人的豆:

 <bean id="dataSource" 
     class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" 
     p:driverClass=" net.sourceforge.jtds.jdbc.Driver" 
     p:jdbcUrl="${jdbc-url}" 
     p:user="${username}" 
     p:password="${password}" 
     /> 

這是不相同的驅動程序類,但正如我已經說過,我認爲你正在使用的數據源類是問題

這裏還有其他各種設置:Data access with JDBC

+1

我知道:-)。 – kmansoor

0

對於底層數據庫,p:driverClassName需要Jdbc驅動程序。在這種情況下,您需要爲MSSQL Server指定驅動程序。