Using bonecp as Tomcat 5.5 datasource

与世无争的帅哥 提交于 2019-12-07 09:09:00

问题


I try to get Tomcat to use BoneCP as a connection pool because DBCP doesn't work correctly here.

I tried to add it to the context.xml that defines my webapp like this:

<Context path="/reports" privileged="true" crossContext="true">

    <Resource name="jdbc/IKOffice"
          type="com.jolbox.bonecp.BoneCPDataSource"
          auth="Container"

          username="ik"
          password="******"
          jdbcUrl="jdbc:postgresql://localhost:5434/IKOffice_Core"

          lazyInit="true"
          partitionCount="1" 
          ... more properties ...
          logStatementsEnabled="false" />

</Context>

But when I try to access the resource, it always says:

javax.naming.NamingException: Cannot create resource instance

There are no errors in the logfile, and all required jars are available to the webapp. What is going on here?

Everything worked when I used a resource like this:

     <Resource name="jdbc/IKOffice"
          auth="Container"
          type="javax.sql.DataSource"
          username="ik"
          password="******"
          driverClassName="org.postgresql.Driver"
          url="jdbc:postgresql://localhost:5434/IKOffice_Core"
          maxActive="8"
          maxIdle="4" />

SOLUTION:

You have to specify a BeanFactory, like this (line 3):

 <Resource name="jdbc/IKOffice"
          type="jcom.jolbox.bonecp.BoneCPDataSource"
          factory="org.apache.naming.factory.BeanFactory"
          auth="Container"
          ...

回答1:


Tomcat uses factories to create JNDI resources. For a limited number of resource types (including javax.sql.DataSource) Tomcat knows it can use a built-in factory. For unknown resource types (such as jcom.jolbox.bonecp.BoneCPDataSource) you need to specify the factory to be used to create the resource.



来源:https://stackoverflow.com/questions/9905871/using-bonecp-as-tomcat-5-5-datasource

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!