NamingException: no resource registered with uniqueName 'jdbc/mydatasource'

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

NamingException: no resource registered with uniqueName 'jdbc/mydatasource'

Doug Reeder
I am trying to use BTM with the Derby embedded driver in Tomcat 6.0.16.  I'm running with a $CATALINA_BASE separate from $CATALINA_HOME.  (I'm working in NetBeans 6.1.)

For Derby, I JARed examples.tutorial.derby.ServerLifecycleListener.class and copied that jar,  derby.jar and derbytools.jar to $CATALINA_HOME/lib.  To $CATALINA_BASE/conf/server.xml, I added the line <Listener className="examples.tutorial.derby.ServerLifecycleListener" /> .  Webapps that just use Derby work fine.

To get logging for BTM working, I copied slf-api-1.5.3.jar and slf4j-jdk14-1.5.3.jar to $CATALINA_HOME/lib

For BTM itself, I copied btm-1.1.jar and geronimo-jta_1.1.1B_spec-1.0.1.jar to $CATALINA_BASE/common/lib.  

I created a file named setenv.sh in $CATALINA_HOME/bin, which contains 
CATALINA_OPTS="-Dbtm.root=$CATALINA_BASE -Dbitronix.tm.configuration=$CATALINA_BASE/conf/btm-config.properties"

I created a file named btm-config.properties in $CATALINA_BASE/conf/ directory containing
bitronix.tm.serverId=tomcat-btm-node0
bitronix.tm.journal.disk.logPart1Filename=${btm.root}/work/btm1.tlog
bitronix.tm.journal.disk.logPart2Filename=${btm.root}/work/btm2.tlog
bitronix.tm.resource.configuration=${btm.root}/conf/resources.properties

I created a file named resources.properties in $CATALINA_BASE/conf/ directory
resource.ds1.className=org.apache.derby.jdbc.EmbeddedXADataSource
resource.ds1.uniqueName=jdbc/mydatasource
resource.ds1.minPoolSize=0
resource.ds1.maxPoolSize=5
resource.ds1.driverProperties.databaseName=db1
resource.ds1.driverProperties.createDatabase=create

I created a webapp named TomcatTransaction, and to context.xml, I added
    <Resource name="jdbc/mydatasource" auth="Container" type="javax.sql.DataSource"
        factory="bitronix.tm.resource.ResourceObjectFactory" uniqueName="jdbc/mydatasource" />

    <Transaction factory="bitronix.tm.BitronixUserTransactionObjectFactory" />

To web.xml, I added
    <resource-env-ref>
        <resource-env-ref-name>jdbc/mydatasource</resource-env-ref-name>
        <resource-env-ref-type>javax.sql.DataSource</resource-env-ref-type>
    </resource-env-ref>

I created a servlet called Accessor, which has the doGet method:
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet Accessor</title>");
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet Accessor at " + request.getContextPath() + "</h1>");

            try {
                InitialContext ic = new InitialContext();
                DataSource mydatasource = (DataSource) ic.lookup("java:comp/env/jdbc/mydatasource");
            } catch (NamingException ex) {
                out.println("<p>" + ex + "</p>");
            }

            out.println("</body>");
            out.println("</html>");
        } finally {
            out.close();
        }
    }


When I start up Tomcat, I get a NamingException for jdbc/mydatasource:

Oct 15, 2008 1:33:01 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: .:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java
Oct 15, 2008 1:33:01 AM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8084
Oct 15, 2008 1:33:01 AM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 491 ms
Derby JDBC driver loaded successfully
Oct 15, 2008 1:33:01 AM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Oct 15, 2008 1:33:01 AM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.16
Oct 15, 2008 1:33:02 AM org.apache.catalina.core.NamingContextListener addResource
WARNING: Failed to register in JMX: javax.naming.NamingException: no resource registered with uniqueName 'jdbc/mydatasource', available resources: []
Oct 15, 2008 1:33:02 AM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8084
Oct 15, 2008 1:33:02 AM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Oct 15, 2008 1:33:02 AM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/31  config=null
Oct 15, 2008 1:33:02 AM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1102 ms


When I try deploy the servlet, I again get the NamingException:
Oct 15, 2008 1:35:13 AM org.apache.catalina.startup.HostConfig checkResources
INFO: Undeploying context [/TomcatTransaction]
Oct 15, 2008 1:35:13 AM org.apache.catalina.core.NamingContextListener addResource
WARNING: Failed to register in JMX: javax.naming.NamingException: no resource registered with uniqueName 'jdbc/mydatasource', available resources: []
Oct 15, 2008 1:35:13 AM org.apache.catalina.core.StandardContext start
INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/TomcatTransaction] has already been started


And when I run the servlet, I again get the NamingException:

Servlet Accessor at /TomcatTransaction

javax.naming.NamingException: no resource registered with uniqueName 'jdbc/mydatasource', available resources: []


What do I need to do get jdbc/mydatasource properly registered?


Reply | Threaded
Open this post in threaded view
|

Re: NamingException: no resource registered with uniqueName 'jdbc/mydatasource'

Ludovic Orban
Administrator
Hi,

It looks like you're using a mix of BTM 1.2 and 1.3 instructions. I know, I should have updated the documentation for 1.3 long ago but I'm lacking time.

I would advise you to upgrade to BTM 1.3.1 (download it from here: http://docs.codehaus.org/display/BTM/Download) and use the btm-tomcat55-lifecycle.jar available in the integration folder of the distribution instead of writing your own lifecycle (it also works with tomcat 6.x).

I also noticed you copied some libs in $CATALINA_BASE/common/lib. I guess you mean $CATALINA_BASE/lib as the common/lib folder disappeared in Tomcat 6. Also make sure $CATALINA_BASE points to the right folder as I noticed the startup scripts changed a bit since version 5.5.

Integrating a transaction manager in Tomcat is a painful process, you'll certainly have to try a lot of times before you get it right.

Let me know if that helps.
Ludovic
Reply | Threaded
Open this post in threaded view
|

Re: NamingException: no resource registered with uniqueName 'jdbc/mydatasource'

Doug Reeder
I'm using 1.3.1, and the directions at http://docs.codehaus.org/display/BTM/Tomcat 
.

Is there any documentation on how to use btm-tomcat55-
lifecycle.jar ?   Will I need to go through the jar to find out what's  
in there and read the JavaDocs on those classes? I have the JavaDocs,  
but there's no obvious usage directions.

$CATALINA_BASE/common/lib does not exist by default, but Tomcat uses  
it if you create it.


On Oct 15, 2008, at 7:05 AM, Ludovic Orban wrote:

>
> Hi,
>
> It looks like you're using a mix of BTM 1.2 and 1.3 instructions. I  
> know, I
> should have updated the documentation for 1.3 long ago but I'm  
> lacking time.
>
> I would advise you to upgrade to BTM 1.3.1 (download it from here:
> http://docs.codehaus.org/display/BTM/Download) and use the
> btm-tomcat55-lifecycle.jar available in the integration folder of the
> distribution instead of writing your own lifecycle (it also works with
> tomcat 6.x).
>
> I also noticed you copied some libs in $CATALINA_BASE/common/lib. I  
> guess
> you mean $CATALINA_BASE/lib as the common/lib folder disappeared in  
> Tomcat
> 6. Also make sure $CATALINA_BASE points to the right folder as I  
> noticed the
> startup scripts changed a bit since version 5.5.
>
> Integrating a transaction manager in Tomcat is a painful process,  
> you'll
> certainly have to try a lot of times before you get it right.
>
> Let me know if that helps.
> Ludovic
> --

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|

Re: NamingException: no resource registered with uniqueName 'jdbc/mydatasource'

Ludovic Orban
Administrator
Doug,

The http://docs.codehaus.org/display/BTM/Tomcat page is specific to BTM 1.2 and earlier.

I've just finished the 1.3 equivalent of that page, it is here: http://docs.codehaus.org/display/BTM/Tomcat13

Please follow it line by line as any little mistake might make the entire setup fail and is painful to track down.

Ludovic