Results 1 to 2 of 2

Thread: Publish a spring-managed DataSource to JNDI

  1. #1
    Join Date
    Aug 2004
    Location
    San Francisco, CA
    Posts
    66

    Default Publish a spring-managed DataSource to JNDI

    I'm using a spring managed DataSource throughout my web application. The data source is a C3P0 connection pool using the jDTS JDBC driver to connect to a MS SQl Server database. All of this happens under Tomcat 5.0.28. Everything is good in the world...

    Code:
    <bean id="pooledDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    		<property name="driverClass"><value>$&#123;jdbc.driverClassName&#125;</value></property>
    		<property name="jdbcUrl"><value>$&#123;jdbc.url&#125;</value></property>
    		<property name="user"><value>$&#123;jdbc.username&#125;</value></property>
    		<property name="password"><value>$&#123;jdbc.password&#125;</value></property>
    </bean>
    So, now we've starting using Crystal Reports to generate reports, and there doesn't seem to be a way to hand it a DataSource programmatically (i.e. setDataSource(...)). The only way to effectively give it a DataSource is by making the DataSource available via JNDI.

    Is there a way to have spring "publish" (not sure what the terminology is) a DataSource it is managing to JNDI or do I have to create the DataSource and place it in JNDI myself, and then use JndiObjectFactoryBean?

    I really like keeping everything spring managed for consistency's sake. And I think that if I go the second route, I'll have to drop my JDBC and C3P0 jars into common/lib... we generally try to keep all jars for a web app with the web app.

    Any ideas?

    Christian

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    You'll need to write some custom code. Easiest solution is probably an object that takes the DataSource as a property or in a constructor arg, and binds it to JNDI. You can use Spring's JndiTemplate to simplify the binding process.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

Similar Threads

  1. Replies: 7
    Last Post: Aug 29th, 2011, 05:01 AM
  2. Replies: 13
    Last Post: Feb 5th, 2010, 12:31 AM
  3. JBoss DataSource not found
    By moacsjr in forum Data
    Replies: 10
    Last Post: Aug 25th, 2005, 01:26 PM
  4. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  5. Ignoring missing Jndi DataSource within IDE?
    By Bill Pearce in forum Container
    Replies: 2
    Last Post: Oct 27th, 2004, 09:06 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •