commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mattias J <>
Subject Re: [Slightly OT] JNDI question
Date Wed, 04 May 2005 06:46:53 GMT
This is how we do it and it works fine.
Spring provides lots of stuff that makes testing easier. I should have a 
more thorough look at it myself someday...

At 2005-05-03 20:38, you wrote:
>Stumbled across this just recently: Spring has a "mock" JNDI 
>implementation.  Create  your datasource, bind it into the mock JNDI tree, 
>activate it and off you go.  Note that this class is in the spring-mock 
>JAR, not the regular spring JAR.  Class documentation is at 

>Here's an example (we used a mock datasource, but you get the idea).
>      SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder();
>      MockDataSource mockDataSource = new MockDataSource();
>      builder.bind("jdbc/foo", mockDataSource);
>      builder.activate();
>So, if you can't "inject" the datasource then here's a nice and easy JNDI 
>implementation that you can use.
>>>I'm wondering if somone has any creative ideas here.  I'm working on a 
>>>project that gets javax.sql.DataSource instances via Tomcat's JNDI 
>>>provider.  This works fine, except when we are developing code and need 
>>>to run Junit tests.
>>>Because the tests need to run outside Tomcat, getting access to a 
>>>DataSource via JNDI becomes a pain in the neck.
>>>I'm assuming that this is a very common situation and I'm wondering if 
>>>anybody has slick tricks for your dev environments that allow you do get 
>>>DataSource objects via JNDI...?

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message