Creating a 'jdbc' context for an mbean containing C3P0 pooed
ddkilzer Jan 5, 2006 4:11 PMWhen I first set up my application to run under JBossAS, I created an mssql-ds.xml file that provided a datasource in JNDI named "jdbc/dbname":
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE datasources PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN" "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd"> <datasources> <local-tx-datasource> <jndi-name>jdbc/dbname</jndi-name> <connection-url>jdbc:jtds:sqlserver://hostname/dbname</connection-url> <driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class> <connection-property name="domain"></connection-property> <user-name>user</user-name> <password>pass</password> </local-tx-datasource> </datasources>
However, this datasource was not pooled, so I wanted to set up a pooled datasource using C3P0 at the same JNDI name.
http://www.mchange.com/projects/c3p0/index.html#appendix_e
Here is the c3p0-service.xml file I used:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE server PUBLIC "-//JBoss//DTD MBean Service 4.0//EN" "http://www.jboss.org/j2ee/dtd/jboss-service_4_0.dtd"> <server> <mbean code="com.mchange.v2.c3p0.mbean.C3P0PooledDataSource" name="jboss:service=C3P0PooledDataSource1"> <attribute name="JndiName">java:jdbc/dbname</attribute> <attribute name="JdbcUrl">jdbc:jtds:sqlserver://hostname/dbname</attribute> <attribute name="DriverClass">net.sourceforge.jtds.jdbc.Driver</attribute> <attribute name="User">user</attribute> <attribute name="Password">pass</attribute> <attribute name="TestConnectionOnCheckout">true</attribute> <depends>jboss:service=Naming</depends> </mbean> </server>
Unfortunately, when starting JBoss AS 4.0.2, I get the following error:
To the log file JBoss wrote:
12:59:54,516 ERROR [URLDeploymentScanner] Incomplete Deployment listing:
--- MBeans waiting for other MBeans ---
ObjectName: jboss:service=C3P0PooledDataSource1
State: FAILED
Reason: org.jboss.deployment.DeploymentException: Exception setting attribute javax.management.Attribute: name=JndiName value=jdbc/dbname on mbean jboss:service=C3P0PooledDataSource1; - nested throwable: (javax.naming.NameNotFoundException: jdbc not bound)
--- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
ObjectName: jboss:service=C3P0PooledDataSource1
State: FAILED
Reason: org.jboss.deployment.DeploymentException: Exception setting attribute javax.management.Attribute: name=JndiName value=jdbc/dbname on mbean jboss:service=C3P0PooledDataSource1; - nested throwable: (javax.naming.NameNotFoundException: jdbc not bound)
I've tried the following values for the "JndiName" attribute, all without success:
- java:jdbc/dbname
- java:/jdbc/dbname
- java:comp/env/jdbc/dbname
The only "JndiName" that works so far as been a top-level JNDI name like these:- java:dbname
- java:dbnameDS
What do I have to do to get the C3P0 mbean to set up JNDI resources under "jdbc" or "comp/env/jdbc", similar to the way that the original *-ds.xml file did?
Note that I originally thought this was a bug, but apparently it's not:
http://jira.jboss.com/jira/browse/JBAS-2630
Thanks!
Dave