Results 1 to 5 of 5

Thread: JNDI DataSource lookup outside of JBoss

  1. #1
    Join Date
    Mar 2005
    Posts
    11

    Default JNDI DataSource lookup outside of JBoss

    I would like to configure my DataSources in a central place and provide them to client apps via JNDI. So I've set up the JCA configuration in JBoss (and made sure its in the global namespace). I have also been able to get a DBCP BasicDataSource configured with Spring to work. When I try to use the JNDI DataSource, I get the following stack trace (the TypeMismatchException is the culprit):

    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [D:\cwn\da\conf\spring-hub-config.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyAccessExceptionsException: PropertyAccessExceptionsException (1 errors); nested propertyAccessExceptions are: [org.springframework.beans.TypeMismatchException: Failed to convert property value of type [javax.naming.Reference] to required type [javax.sql.DataSource] for property 'dataSource']
    PropertyAccessExceptionsException (1 errors)
    org.springframework.beans.TypeMismatchException: Failed to convert property value of type [javax.naming.Reference] to required type [javax.sql.DataSource] for property 'dataSource'
    	at org.springframework.beans.BeanWrapperImpl.doTypeConversionIfNecessary(BeanWrapperImpl.java:1035)
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:803)
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:716)
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:844)
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:871)
    	at org.springframework.beans.BeanWrapperImpl.setPropertyValues(BeanWrapperImpl.java:860)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:926)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:727)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:336)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:223)
    	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:271)
    	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:312)
    	at org.springframework.context.support.FileSystemXmlApplicationContext.<init>&#40;FileSystemXmlApplicationContext.java&#58;82&#41;
    	at org.springframework.context.support.FileSystemXmlApplicationContext.<init>&#40;FileSystemXmlApplicationContext.java&#58;67&#41;
    	at com.shps.da.spring.AbstractSpringUnitTest.setUp&#40;AbstractSpringUnitTest.java&#58;42&#41;
    	at junit.framework.TestCase.runBare&#40;TestCase.java&#58;125&#41;
    	at junit.framework.TestResult$1.protect&#40;TestResult.java&#58;106&#41;
    	at junit.framework.TestResult.runProtected&#40;TestResult.java&#58;124&#41;
    	at junit.framework.TestResult.run&#40;TestResult.java&#58;109&#41;
    	at junit.framework.TestCase.run&#40;TestCase.java&#58;118&#41;
    	at junit.framework.TestSuite.runTest&#40;TestSuite.java&#58;208&#41;
    	at junit.framework.TestSuite.run&#40;TestSuite.java&#58;203&#41;
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests&#40;RemoteTestRunner.java&#58;436&#41;
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run&#40;RemoteTestRunner.java&#58;311&#41;
    	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main&#40;RemoteTestRunner.java&#58;192&#41;
    My DataSource config in Spring:

    Code:
    <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName">
            <value>jdbc/SdsrDS</value>
        </property>
        <property name="resourceRef">
            <value>false</value>
        </property>
    </bean>

  2. #2
    Join Date
    Jun 2005
    Location
    District of Columbia, US
    Posts
    13

    Default

    A resource reference is required to use jndi. Make sure you have the following in web.xml:

    <resource-ref>
    <res-ref-name>jdbc/SdsrDS</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
    </resource-ref>

    For your jndiname property, try replacing the value with java:comp/env/jdbc/SdsrDS
    sami

  3. #3
    Join Date
    Mar 2005
    Posts
    11

    Default

    Assume the calling code is not in a webapp but a stand-alone command line application that will consume JMS messages. That is why I put the JNDI name in the global context instead of the ENC.

  4. #4
    Join Date
    Aug 2004
    Posts
    1,104

    Default

    Aren't you running in a different JVM at that point? How are you going to share a DataSource across JVMs?
    Thomas Risberg
    SpringSource by Pivotal
    http://www.springsource.org

  5. #5
    Join Date
    Mar 2005
    Posts
    11

    Default

    I guess DataSources are not serializable?

Similar Threads

  1. Replies: 13
    Last Post: Feb 5th, 2010, 12:31 AM
  2. Replies: 4
    Last Post: Jan 17th, 2007, 01:01 AM
  3. JBoss DataSource not found
    By moacsjr in forum Data
    Replies: 10
    Last Post: Aug 25th, 2005, 01:26 PM
  4. Replies: 1
    Last Post: Feb 12th, 2005, 07:30 AM
  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
  •