Trouble with context and JNDI resource

View: New views
3 Messages — Rating Filter:   Alert me  

Trouble with context and JNDI resource

by Mike Baranski-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm using this page, trying to get a resource in a java class:

http://tomcat.apache.org/tomcat-6.0-doc/jndi-resources-howto.html

I have this in context.xml:


<Context>

    <!-- Default set of monitored resources -->
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
       
    <!-- Uncomment this to disable session persistence across Tomcat
restarts -->
    <!--
    <Manager pathname="" />
    -->
                <Resource name="proteus" auth="Container"
type="org.apache.commons.dbcp.BasicDataSource"
              maxActive="100" maxIdle="30" maxWait="10000"
              username="install" password="install"
driverClassName="com.informix.jdbc.IfxDriver"
 
url="jdbc:informix-sqli://sigma:1960/proteus:INFORMIXSERVER=sigma;IFX_LOCK_M
ODE_WAIT=-1;IFX_ISOLATION_LEVEL=1">
                </Resource>
</Context>

I have this in web.xml:

<resource-env-ref>
                <description>
                        Connection pool for xmlrpc.
                </description>
                <resource-env-ref-name>
                        proteus
                </resource-env-ref-name>
                <resource-env-ref-type>
                        org.apache.commons.dbcp.BasicDataSource

                </resource-env-ref-type>
</resource-env-ref>

I have this code:

l.debug("Created the status xmlrpc class");
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("");
this.setDataSource((BasicDataSource) envCtx.lookup("proteus"));

I get this error:

Name proteus is not bound in this Context


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: Trouble with context and JNDI resource

by Mikolaj Rydzewski-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Mike Baranski wrote:
> <Resource name="proteus" auth="Container"
> type="org.apache.commons.dbcp.BasicDataSource"
>  
Why not to use jdbc/proteus? Just to follow convention. I'd also rather
use javax.sql.DataSource as type attribute.
> <resource-env-ref-name>
> proteus
> </resource-env-ref-name>
>  
The same, use jdbc/proteus.
> I have this code:
>
> l.debug("Created the status xmlrpc class");
> Context initCtx = new InitialContext();
> Context envCtx = (Context) initCtx.lookup("");
> this.setDataSource((BasicDataSource) envCtx.lookup("proteus"));
>  
What about following:

new InitialContext().lookup("java:comp/env/jdbc/proteus");


--
Mikolaj Rydzewski <miki@...>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


RE: Trouble with context and JNDI resource

by Mike Baranski-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That worked, thanks.

>-----Original Message-----
>From: Mikolaj Rydzewski [mailto:miki@...]
>Sent: Tuesday, November 03, 2009 9:11 AM
>To: Tomcat Users List
>Subject: Re: Trouble with context and JNDI resource
>
>Mike Baranski wrote:
>> <Resource name="proteus" auth="Container"
>> type="org.apache.commons.dbcp.BasicDataSource"
>>
>Why not to use jdbc/proteus? Just to follow convention. I'd also rather
>use javax.sql.DataSource as type attribute.
>> <resource-env-ref-name>
>> proteus
>> </resource-env-ref-name>
>>
>The same, use jdbc/proteus.
>> I have this code:
>>
>> l.debug("Created the status xmlrpc class");
>> Context initCtx = new InitialContext();
>> Context envCtx = (Context) initCtx.lookup("");
>> this.setDataSource((BasicDataSource) envCtx.lookup("proteus"));
>>
>What about following:
>
>new InitialContext().lookup("java:comp/env/jdbc/proteus");
>
>
>--
>Mikolaj Rydzewski <miki@...>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@...
>For additional commands, e-mail: users-help@...


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...