2012-03-09 525 views
1

我想使用BoneCP執行連接池。但我得到了無法加載資源工廠類的日誌。 我得到了這個錯誤日誌上Tomcat啓動無法加載資源工廠類java.lang.ClassNotFoundException:com.jolbox.bonecp.BoneCPDataSource

SEVERE: Exception processing Global JNDI Resources 
javax.naming.NamingException: Could not load resource factory class [Root exception is java.lang.ClassNotFoundException: com.jolbox.bonecp.BoneCPDataSource] 
    at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:81) 
    at javax.naming.spi.NamingManager.getObjectInstance(NamingManager.java:304) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:793) 
    at org.apache.naming.NamingContext.lookup(NamingContext.java:140) 
    at org.apache.naming.NamingContextBindingsEnumeration.nextElementInternal(NamingContextBindingsEnumeration.java:113) 
    at org.apache.naming.NamingContextBindingsEnumeration.next(NamingContextBindingsEnumeration.java:71) 
    at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans(GlobalResourcesLifecycleListener.java:137) 
    at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.createMBeans(GlobalResourcesLifecycleListener.java:109) 
    at org.apache.catalina.mbeans.GlobalResourcesLifecycleListener.lifecycleEvent(GlobalResourcesLifecycleListener.java:81) 
    at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142) 
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:747) 
    at org.apache.catalina.startup.Catalina.start(Catalina.java:595) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
    at java.lang.reflect.Method.invoke(Method.java:597) 
    at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289) 
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414) 
Caused by: java.lang.ClassNotFoundException: com.jolbox.bonecp.BoneCPDataSource 
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251) 
    at org.apache.naming.factory.ResourceFactory.getObjectInstance(ResourceFactory.java:79) 
    ... 17 more 

我已經將資源添加到server.xml中是這樣的。

<GlobalNamingResources> 
    <!-- Editable user database that can also be used by 
     UserDatabaseRealm to authenticate users 
    --> 
    <Resource name="UserDatabase" auth="Container" 
       type="org.apache.catalina.UserDatabase" 
       description="User database that can be updated and saved" 
       factory="org.apache.catalina.users.MemoryUserDatabaseFactory" 
       pathname="conf/tomcat-users.xml" /> 

     <Resource type='javax.sql.DataSource' 
       name='demodb' 
      factory='com.jolbox.bonecp.BoneCPDataSource' 
    driverClassName='oracle.jdbc.driver.OracleDriver' 
      jdbcUrl='jdbc:oracle:thin:@localhost:1521:XE' 
      username='system' 
      password='system' 
     idleMaxAge='240' 
    idleConnectionTestPeriod='60' 
    partitionCount='3' 
    acquireIncrement='5' 
    maxConnectionsPerPartition='10' 
    minConnectionsPerPartition='5' 
      statementsCacheSize='50' 
     releaseHelperThreads='5' 
     /> 
    </GlobalNamingResources> 

誰能告訴我問題是什麼?

回答

0

該例外說明類com.jolbox.bonecp.BoneCPDataSource未找到。你是否確定該類是由服務器或你的應用程序加載的?

應設在這些jars.

希望這有助於之一,玩得開心!

+0

我正在使用NetBeans,我已經在庫中加載了(BoneCP 0.7.1)jar文件,但仍然在服務器啓動時出現此錯誤。 – Hablu 2012-03-12 06:48:15

+0

好的,請確保* BoneCP 0.7.1.jar *由服務器加載,或者通過將其複製到服務器庫目錄中,或者告訴netbeans將其與項目一起導出。我不知道如何在NetBeans中正確執行此操作,但是我發現[this](http://stackoverflow.com/questions/8096232/how-to-have-netbeans-projects-export-their-dependencies-like-eclipse - ),並希望這會讓你走上正軌。乾杯! – SimonSez 2012-03-12 09:07:13

+0

好吧,讓我們假設我手動在庫中添加了該jar文件。 之後,我創建了我的應用程序戰爭文件。如果我必須在聯機服務器上託管該戰爭文件,那麼我如何將該jar文件添加到聯機服務器庫中? – Hablu 2012-03-12 13:40:26

0

你必須加上此行:

 <pathelement location="/path/bonecp-0.7.1.RELEASE.jar"/> 

到類路徑中。如果你想使用Netbeans,請修改路徑。

0

有時,錯誤可能是由於混合罐子。連接池使用自定義類加載器,不會允許來自不同BoneCP/Datanucleus版本的jar。