Announcement Announcement Module
Collapse
No announcement yet.
JBOSS JNDI ResourceRef Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JBOSS JNDI ResourceRef

    Using JNDI Template in Tomcat I was able to get datasources using the configuration below. Unfortunately now that I am using JBoss I get a javax.naming.Reference instance instead, so the below throws an error. Any idea how to get the DataSource identified by the Reference?

    Code:
        <bean id="jndiAccessor" abstract="true">
            <property name="jndiTemplate">
                <bean class="org.springframework.jndi.JndiTemplate">
                    <property name="environment">
                        <bean class="org.springframework.beans.factory.config.PropertiesFactoryBean">
                            <property name="location" value="classpath:jndi.properties" />
                        </bean>
                    </property>
                </bean>
            </property>
            <property name="resourceRef" value="true" />
        </bean>
    
    
        <bean id="dataSource" parent="jndiAccessor" class="org.springframework.jndi.JndiObjectFactoryBean">
            <property name="jndiName" value="jdbc/MyDS" />
        </bean>

  • #2
    You have to name the expected type for your JNDI object through setExpectedType(Class expectedType)

    <bean id="dataSource" parent="jndiAccessor" class="org.springframework.jndi.JndiObjectFactoryB ean">
    <property name="jndiName" value="jdbc/MyDS" />
    <property name="expectedType" value="someClass" />
    </bean>

    Comment


    • #3
      ExpectedType is a DataSource

      When I change the expected type property to javax.sql.DataSource, I get the error information below.

      Previously I was using Tomcat 5 and all I had to do was resourceRef = true and I was able to get the datasource. Because I need to access JNDI from within the web application and from a console application (a simple JMS Consumer Service) I started to use JBoss. Copied the default server to myserver and put in an oracle-ds.xml configuration file to define my data sources. The actual type returned from JNDI in JBoss 4 is javax.naming.Reference. I am using Spring because I want my code to be independent of such differences, but now I cannot even get the Datasource.

      org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'myDS' defined in class path resource [com/myapp/config/beans.xml]: Initialization of bean failed; nested exception is javax.naming.NamingException: Located JNDI object [Reference Class Name: javax.sql.DataSource
      Address Type: ProxyData
      AddressContents: ffffffac ffffffed 0 5 73 7d 0 0 0 1 0 14 6a 61 76 61 78 2e 73 71 6c 2e 44 61 74 61 53 6f 75 72 63 65 ...
      Address Type: VMID
      AddressContents: ffffffac ffffffed 0 5 73 72 0 13 6a 61 76 61 2e 72 6d 69 2e 73 65 72 76 65 72 2e 55 49 44 f 12 70 d ffffffbf ...
      Type: JndiName
      Content: jdbc/MyDS
      ] is not assignable to expected type [javax.sql.DataSource]

      Comment


      • #4
        Check the JNDI space with the jmx browser and see the correct address and the type of your JNDI resource. Check out also the JBoss forums - apparently it's a configuration problem.

        Comment

        Working...
        X