Results 1 to 4 of 4

Thread: JBOSS JNDI ResourceRef

  1. #1
    Join Date
    Dec 2005
    Posts
    2

    Default 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. #2
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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>
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

  3. #3
    Join Date
    Dec 2005
    Posts
    2

    Default 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]

  4. #4
    Join Date
    Jan 2005
    Location
    Bucharest, Romania
    Posts
    5,403

    Default

    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.
    Costin Leau
    SpringSource - http://www.SpringSource.com- Spring Training, Consulting, and Support - "From the Source"
    http://twitter.com/costinl
    Please use [ c o d e ] [ / c o d e ] tags

Posting Permissions

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