Announcement Announcement Module
Collapse
No announcement yet.
Publish a spring-managed DataSource to JNDI Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment

    Working...
    X