Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » Tomcat Users »

Fw: [tomcat 5.5] Reference a JNDI env resource from another env-resource

Alexandre Borgoltz

2004-11-29


Hi,

I have developed my own BeanFactory as explained in your JNDI-RESOURCE-HOWTO.

Everything works fine and I can use the corresponding factory successfully.

But when I try to upgrade it a bit, I'm facing a problem:

I'd like my factory to access a database to update the bean it returns. So I'd like it to use the datasource I've also configured in server.xml:

<GlobalNamingResources>   <Resource  name="jdbc/oracle/sjogmxf" auth="Container"           type="javax.sql.DataSource"           factory="org.apache.commons.dbcp.BasicDataSourceFactory"           driverClassName="oracle.jdbc.driver.OracleDriver"           url="jdbc:oracle:thin:@(protected):

<ResourceLink name="infocenter" type="cosmos.infocenter.Infocenter" global="infocenter"/> <ResourceLink name="jdbc/oracle/sjogmxf" type="javax.sql.DataSource" global="jdbc/oracle/sjogmxf"/>
When I try to lookup and use one of these resources directly from the webapps, it just works great. But if I try to modify my custom factory to make it lookup the datasource, it gets a NamingException (Comp is not linked to the initial context).

I suppose this means the initial context is created after the resources are created. Is there a way to have my custom resource reference another resource (in this case, the datasource)? Then is there a way to specify the order of loading for resources? (Here I'll need the datasource to be loaded BEFORE the custom factory...)

I thank you in advance,

Alexandre BORGOLTZ
Head of Technology

SmartJog SA
Phone: +33 (0)1 4996 6324
Fax: +33 (0)1 4996 6405
Mobile: +33 (0)6 8882 1417
alexandre.borgoltz@(protected)


©2008 junlu.com - Jax Systems, LLC, U.S.A.