Question

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"
          ...
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top