在Mule ESB 3.7.0 CE上 我已经配置了C3P0连接:
<bean id="dbConnection"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="persistenceUnitName" value="${diap6.centraleurope.company}" />
<property name="persistenceXmlLocation" value="${db.persistence.xml}" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="false" />
<property name="showSql" value="${diap6.centraleurope.show_sql}" />
</bean>
</property>
<property name="persistenceUnitPostProcessors">
<list>
<ref bean="entitiesCompanyLoader" />
</list>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider
</prop>
<prop key="hibernate.connection.driver_class">oracle.jdbc.OracleDriver</prop>
<prop key="hibernate.connection.url">${diap6.centraleurope.url}</prop>
<prop key="hibernate.connection.username">t6valce</prop>
<prop key="hibernate.connection.password">t6valce</prop>
<prop key="hibernate.hbm2ddl.auto">false</prop>
<prop key="hibernate.show_sql">${diap6.centraleurope.show_sql}</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle9iDialect</prop>
<prop key="hibernate.c3p0.acquire_increment">2</prop>
<prop key="hibernate.c3p0.idle_test_period">60</prop>
<prop key="hibernate.c3p0.timeout">15</prop>
<prop key="hibernate.c3p0.max_size">10</prop>
<prop key="hibernate.c3p0.max_statements">50</prop>
<prop key="hibernate.c3p0.min_size">0</prop>
<prop key="hibernate.c3p0.maxIdleTime">360</prop>
<prop key="hibernate.c3p0.preferredTestQuery">SELECT 1 from dual</prop>
<prop key="hibernate.c3p0.idleConnectionTestPeriod">30</prop>
<prop key="hibernate.c3p0.acquireRetryDelay">1000</prop>
<prop key="hibernate.connection.autoReconnect">true</prop>
<prop key="hibernate.cache.use_second_level_cache">false</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory
</prop>
</props>
</property>
</bean>
如果我在apps / myapp / lib上放置驱动程序类jar ojdbc6.jar我在应用程序启动时遇到此错误:
WARN 2015-10-16 11:26:01,691 [C3P0PooledConnectionPoolManager[identityToken->z8kfsx9ctrp0kk4mc5wl|456c58cd]-HelperThread-#0] com.mchange.v2.resourcepool.BasicResourcePool: com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@13c79966 -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed acquisition attempts (30). Last acquisition attempt exception:
java.sql.SQLException: No suitable driver
at java.sql.DriverManager.getDriver(DriverManager.java:315) ~[?:1.8.0_60]
at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:285) ~[c3p0-0.9.5.jar:0.9.5]
at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175) ~[c3p0-0.9.5.jar:0.9.5]
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220) ~[c3p0-0.9.5.jar:0.9.5]
at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206) ~[c3p0-0.9.5.jar:0.9.5]
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:200) ~[c3p0-0.9.5.jar:0.9.5]
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1127) ~[c3p0-0.9.5.jar:0.9.5]
at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1114) ~[c3p0-0.9.5.jar:0.9.5]
at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:44) ~[c3p0-0.9.5.jar:0.9.5]
at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1855) ~[c3p0-0.9.5.jar:0.9.5]
at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696) ~[mchange-commons-java-0.2.9.jar:0.2.9]
如果我把jar放在mule系统库中:mule-standalone-3.7.0 / lib / opt找到驱动程序并且应用程序正确启动。
我更喜欢将驱动程序与应用程序捆绑在一起,但似乎是不可能的。你有什么解决方案吗?谢谢。
答案 0 :(得分:0)
我认为它是关于类加载器问题的。 c3p0库在mule-standalone-3.7.0 / lib / opt上,因此,当它调用java.sql.DriverManager.getDriver时,类驱动程序检查mule上下文,同时驱动程序由应用程序级别的其他类加载器加载。 如果我将oracle驱动程序放在mule-standalone-3.7.0 / lib / opt上,则c3p0和oracle驱动程序都属于同一个类加载器,并且getDriver()方法运行良好。