Announcement Announcement Module
Collapse
No announcement yet.
JNDI DataSource lookup outside of JBoss Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


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

      Comment


      • #4
        Aren't you running in a different JVM at that point? How are you going to share a DataSource across JVMs?

        Comment


        • #5
          I guess DataSources are not serializable?

          Comment

          Working...
          X