This is how we do it in a spring app, with a resourcelink in context.xml

conf/server.xml

<GlobalNamingResources>  
  <Resource auth="Container"    
            driverClassName="oracle.jdbc.OracleDriver"    
            maxActive="10"    
            maxIdle="5"    
            maxWait="10000"    
            name="jdbc/oraclePool"    
            username="myuser"  
            password="notapassword"    
            type="javax.sql.DataSource"    
            url="jdbc:oracle:thin:@myhost.acme.com:1521:TEST"    
  />  
</GlobalNamingResources>  

META-INF/context.xml

<?xml version="1.0" encoding="UTF-8"?>
<Context>
  <ResourceLink name="jdbc/oraclePool" type="javax.sql.DataSource"
global="jdbc/oraclePool"/>
</Context>

WEB-INF/applicationContext.xml

<bean id="dataSource"
class="org.springframework.jndi.JndiObjectFactoryBean">
    <property name="jndiName" value="jdbc/oraclePool" /> 
    <property name="resourceRef" value="true" />
</bean>


-----Original Message-----
From: Abid Hussain [mailto:dilax.huss...@googlemail.com] 
Sent: Tuesday, 14 December 2010 5:19 a.m.
To: users@tomcat.apache.org
Subject: How to configure JNDI resource

Hi all,

I've a question about how to configure a datasource to be accessed via
JNDI.

I have a datasource configured in server.xml (In
Server/GlobalNamingResources/Resource).

In the documentation
http://tomcat.apache.org/tomcat-6.0-doc/config/context.html#Resource_Def
initions
it says that that a resource/datasource can be declared in the context
element of a webapp like this:
<Context ...>
  ...
  <Resource name="jdbc/EmployeeDB" auth="Container"
type="javax.sql.DataSource"
     description="Employees Database for HR Applications"/>
  ...
</Context>

Also it is written that it is possible to declare a resource inside
web.xml:
<resource-ref>
  <description>Employees Database for HR Applications</description>
  <res-ref-name>jdbc/EmployeeDB</res-ref-name>
  <res-ref-type>javax.sql.DataSource</res-ref-type>
  <res-auth>Container</res-auth>
</resource-ref>

My question is:
1) is it enough to declare the needed resource inside web.xml or
2) do I have to declare it also in the context element for accessing it
via JNDI?

And, if 2) is correct what is the use to declare a resouce in the
webapps web.xml when it has been already declared in the context element
of the webapp?

Regards,

Abid

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to