Announcement Announcement Module
Collapse
No announcement yet.
Issue with JNDI dataSource loading Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Issue with JNDI dataSource loading

    I'm getting an Error while trying to configure a JNDI dataSource for my Web Application. The dataSource will be used by iBATIS. I'm trying to deploy in Weblogic 9.2.

    The JNDI is correctly configured and from a simple JSP I can access to the property with
    Code:
    Context ctx = new InitialContext();
    Object bean = ctx.lookup("oracle/datasource");
    There is a problem when I try to create a bean with the dataSource with a JndiObjectFactoryBean:

    Code:
    org.springframework.beans.PropertyBatchUpdateException;
    nested PropertyAccessExceptions (1) are: 
    PropertyAccessException 1: org.springframework.beans.TypeMismatchException:
    Failed to convert property value of type [weblogic.jndi.internal.WLEventContextImpl] to required type [javax.sql.DataSource] for property 'dataSource';
    nested exception is java.lang.IllegalArgumentException:
    Cannot convert value of type [weblogic.jndi.internal.WLEventContextImpl] to required type [javax.sql.DataSource] for property 'dataSource': no matching editors or conversion strategy found
    My bean definition code:

    Code:
    <bean id="dataSource-metadata" class="org.springframework.jndi.JndiObjectFactoryBean">
       <property name="jndiName">
          <value>oracle/datasource</value>
       </property>
    </bean>
    
    <bean id="sqlMapClient-metadata" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
       <property name="dataSource">
          <ref bean="dataSource-metadata"/>
       </property>
       <property name="configLocation">
          <value>classpath:/ibatis/sqlmap-config-metadata.xml</value>
       </property>
    </bean>
    Any idea what can be wrong? Thanks

  • #2
    Try to change your bean dataSource-metadata defintion as:

    Code:
    <bean id="dataSource-metadata" class="org.springframework.jndi.JndiObjectFactoryBean">
       <property name="jndiName" value="oracle/datasource" />
    </bean>

    Comment


    • #3
      Both configuration should issue the same result as the are resulting in the same bean.

      You can retrieve an object, you also get an object however it is not a datasource so either there is something wrong or you are using a different location. 'oracle/datasource' is translated to 'java:comp/env/oracle/datasource' you might try the full name with and without the env (it sometimes differs per app server what the root path is).

      Comment


      • #4
        Thanks for the fast answers.

        It seems that its actually finding the object (without the java:comp/env prefix), but there is some kind of trouble while accesing it.

        After introducing some changes my application now deploys on WebLogic. The new bean declaration is:

        Code:
        <bean id="dataSource-metadata" class="org.springframework.jndi.JndiObjectFactoryBean">
           <property name="jndiName">
              <value>oracle/datasource</value>
           </property>
           <property name="lookupOnStartup" value="true"></property>
           <property name="cache" value="true"></property>
           <property name="proxyInterface" value="javax.sql.DataSource"></property>
        </bean>
        But still fails while accessing the dataSource:

        Code:
        org.springframework.aop.AopInvocationException: 
        AOP configuration seems to be invalid: tried calling method [public abstract java.sql.Connection javax.sql.DataSource.getConnection() 
        throws java.sql.SQLException] on target [EventContext (aemsc.oracle.datasource)]; 
        nested exception is java.lang.IllegalArgumentException: EventContext (aemsc.oracle.datasource)
        	at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:289)
        	at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:199)
        	at $Proxy169.getConnection(Unknown Source)
        	at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:112)
        	at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
        	at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:516)
        	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:583)
        	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:608)
        	at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:640)
        	at org.springframework.jdbc.object.SqlQuery.execute(SqlQuery.java:111)
        	at org.springframework.jdbc.object.SqlQuery.execute(SqlQuery.java:198)
        	at org.springframework.jdbc.object.SqlQuery.execute(SqlQuery.java:206)
        ...
        I'm not sure if it might be related with the TransactionManager, I've tried with and without JTA with no luck:

        Code:
        <bean id="transactionManager-metadata" 
           class="org.springframework.transaction.jta.WebLogicJtaTransactionManager">
        </bean>
        Code:
        <bean id="transactionManager-metadata" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
           <property name="dataSource">
              <ref bean="dataSource-metadata"/>
           </property>
        </bean>
        Any suggestions?

        Comment


        • #5
          Sigh... I suggest you check the stacktrace... It is finding SOMETHING but it is not finding a javax.sql.Datasource but another object.

          Comment


          • #6
            Solution found

            I finally discovered what I was doing wrong. The bean definition should be a bit different:

            Code:
            <bean id="dataSource-metadata" class="org.springframework.remoting.rmi.JndiRmiProxyFactoryBean">
               <property name="jndiName" value="oracle/datasource"/>
                  <property name="jndiEnvironment">
                     <props>
                        <prop key="java.naming.factory.url.pkgs">weblogic.jndi.factories</prop>
                     </props>
                  </property>
               <property name="serviceInterface" value="javax.sql.DataSource"/>
            </bean>
            There is an example on this URL: http://www.oracle.com/technology/pub...tegration.html

            Thanks for your help

            Comment

            Working...
            X