Topic
8 replies Latest Post - ‏2012-12-06T20:22:34Z by SystemAdmin
SystemAdmin
SystemAdmin
590 Posts
ACCEPTED ANSWER

Pinned topic Failed to create datasource jndi reference at Spring and Liberty profile

‏2012-12-05T14:19:46Z |
I'm trying to create data source at server.xml file same I have referenced to create beans at spring context.
server.xml

<library id="DB2JCC4Lib">
<fileset dir="D:\\Liberty\\wlp\\DB2DriverLib" includes="db2-jcc-4-2.8.46.jar db2-jcc-license-4-2.8.46.jar"/>
</library>

<dataSource id="dataSourceActual" jndiName="jdbc/DataSourceActual">
<jdbcDriver libraryRef="DB2JCC4Lib"/>
<properties.db2.jcc
databaseName="BLMFIT"
serverName="xxxxx"
portNumber="50000"
currentSchema="BLMFIT"
user="xxxxx"
password="xxxxx"
/>
<connectionManager maxPoolSize="20" minPoolSize="5" />
</dataSource>

Spring context:

1) Referring using org.springframework.jndi.JndiObjectFactoryBean
<bean id="sdpDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="jdbc/DataSourceActual"/>
<property name="resourceRef" value="false"/>
and also tried with java:
<bean id="sdpDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName" value="java:jdbc/DataSourceActual"/>
<property name="resourceRef" value="false"/>
2) Referring using jee:jndi-lookup
<jee:jndi-lookup id="sdpDataSource" jndi-name="jdbc/DataSourceActual" expected-type="javax.sql.DataSource"/>
and also tried with java:
<jee:jndi-lookup id="sdpDataSource" jndi-name="java:jdbc/DataSourceActual" expected-type="javax.sql.DataSource"/>

sdpDataSource reference using like below:
<bean id="dataSource" class="com.macys.platform.util.db.datasource.MonitoredDataSourceFactoryBean">
<constructor-arg ref="sdpDataSource"/>
<constructor-arg value="${macys.database.monitor}"/>
</bean>

Error Log:


org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource http://META-INF/spring/datasource.util.beans.xml: Cannot resolve reference to bean 'sdpDataSource' while setting constructor argument; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sdpDataSource': Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: The calling code's BundleContext could not be determined.
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:328)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:106)
at org.springframework.beans.factory.support.ConstructorResolver.resolveConstructorArguments(ConstructorResolver.java:630)
at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:148)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1003)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:907)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
at com.macys.platform.util.spring.nested.RegistryBean.resolve(RegistryBean.java:90)
at com.macys.platform.util.spring.nested.RegistryBean$ExportBeanTargetSource.getTarget(RegistryBean.java:31)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:182)
at $Proxy11.getConnection(Unknown Source)
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111)
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77)
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:572)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:636)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:665)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:673)
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:713)
at com.macys.platform.util.customdate.dataaccess.CustomDateDAO.getCustomDate(CustomDateDAO.java:76)
at com.macys.platform.util.customdate.cache.CustomDateCacheLoader.load(CustomDateCacheLoader.java:17)
at com.macys.platform.util.caching.transactional.impl.factory.util.TransactionalCacheLoader$1.call(TransactionalCacheLoader.java:59)
at com.macys.platform.util.caching.transactional.impl.manager.TransactionalNamedCachesManagerImpl.invokeAs(TransactionalNamedCachesManagerImpl.java:221)
at com.macys.platform.util.caching.transactional.impl.factory.util.TransactionalCacheLoader.load(TransactionalCacheLoader.java:57)
at com.macys.platform.util.caching.transactional.impl.factory.util.LoggingCacheLoaderWrapper.load(LoggingCacheLoaderWrapper.java:27)
at com.macys.platform.util.caching.transactional.impl.factory.util.CountingCacheLoaderWrapper.load(CountingCacheLoaderWrapper.java:22)
at com.macys.platform.util.caching.factory.NamedCacheFactoryBean$Loader.load(NamedCacheFactoryBean.java:318)
at com.tangosol.net.cache.ReadWriteBackingMap$CacheLoaderCacheStore.load(ReadWriteBackingMap.java:5181)
at com.tangosol.net.cache.ReadWriteBackingMap$CacheStoreWrapper.load(ReadWriteBackingMap.java:4329)
at com.tangosol.net.cache.ReadWriteBackingMap$CacheStoreWrapper.loadInternal(ReadWriteBackingMap.java:4002)
at com.tangosol.net.cache.ReadWriteBackingMap.get(ReadWriteBackingMap.java:754)
at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache.onGetRequest(DistributedCache.CDB:22)
at com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.DistributedCache$GetRequest.run(DistributedCache.CDB:1)
at com.tangosol.coherence.component.util.DaemonPool$WrapperTask.run(DaemonPool.CDB:1)
at com.tangosol.coherence.component.util.DaemonPool$WrapperTask.run(DaemonPool.CDB:32)
at com.tangosol.coherence.component.util.DaemonPool$Daemon.onNotify(DaemonPool.CDB:63)
at com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:42)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sdpDataSource': Invocation of init method failed; nested exception is javax.naming.NoInitialContextException: The calling code's BundleContext could not be determined.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:322)
... 41 more
Caused by: javax.naming.NoInitialContextException: The calling code's BundleContext could not be determined.
at org.apache.aries.jndi.OSGiInitialContextFactoryBuilder.getInitialContext(OSGiInitialContextFactoryBuilder.java:46)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:316)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at org.springframework.jndi.JndiTemplate$1.doInContext(JndiTemplate.java:154)
at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:87)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:152)
at org.springframework.jndi.JndiTemplate.lookup(JndiTemplate.java:178)
at org.springframework.jndi.JndiLocatorSupport.lookup(JndiLocatorSupport.java:95)
at org.springframework.jndi.JndiObjectLocator.lookup(JndiObjectLocator.java:105)
at org.springframework.jndi.JndiObjectFactoryBean.lookupWithFallback(JndiObjectFactoryBean.java:201)
at org.springframework.jndi.JndiObjectFactoryBean.afterPropertiesSet(JndiObjectFactoryBean.java:187)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417)
... 48 more

Please help resolve this issue, Thanks in Advance...
  • SystemAdmin
    SystemAdmin
    590 Posts
    ACCEPTED ANSWER

    Re: Failed to create datasource jndi reference at Spring and Liberty profile

    ‏2012-12-05T15:15:01Z  in response to SystemAdmin
    Hi,

    Have you included the jndi-1.0 feature into the server configuration? Without this feature you will not be able to do a JNDI lookup of data sources.

    Thanks
    Alasdair
    • Jacek_Laskowski
      Jacek_Laskowski
      133 Posts
      ACCEPTED ANSWER

      Re: Failed to create datasource jndi reference at Spring and Liberty profile

      ‏2012-12-05T22:36:04Z  in response to SystemAdmin
      Hi,

      Just for some self-education I decided to create a simple web application with a servlet that does the following:
      
      
      
      try 
      { 
      
      new InitialContext().lookup(
      "anything"); 
      } 
      
      catch (NamingException e) 
      { e.printStackTrace(); 
      }
      

      Not much, but it was for seeing the error message only.

      I let the server run with the servlet-3.0 feature only. The servlet caused the following error message:
      
      [err] javax.naming.NoInitialContextException: Need to specify 
      
      class name in environment or system property, or as an applet parameter, or in an application resource file:  java.naming.factory.initial [err]      at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662) [err]       at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307) [err]         at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:344) [err]    at javax.naming.InitialContext.lookup(InitialContext.java:411) [err]    at wlp.HelloServlet.doGet(HelloServlet.java:19)
      

      Now I wonder why the error message of mine and the author's differ for the following line:
      
      at org.apache.aries.jndi.OSGiInitialContextFactoryBuilder.getInitialContext(OSGiInitialContextFactoryBuilder.java:46)
      

      There are also the differences in the line numbers for javax.naming.* classes, but I suspect it's for the different versions of WLP. What about the OSGiInitialContextFactoryBuilder?! How did that come up in the stack trace? I also ran the sample servlet in a WAB and the stack trace was the same as for the non-OSGi web app's case above.

      Could anyone shed some light on this?

      Jacek
      Japila :: verba docent, exempla trahunt
      • SystemAdmin
        SystemAdmin
        590 Posts
        ACCEPTED ANSWER

        Re: Failed to create datasource jndi reference at Spring and Liberty profile

        ‏2012-12-05T23:46:21Z  in response to Jacek_Laskowski
        Hi,

        My previous post should be ignored. If I had paid more attention I would have realised the exception shown only appears if the jndi-1.0 feature is enabled.

        When jndi-1.0 is enabled we add additional feature components into the runtime to enable the use of JNDI from applications. The integration logic changes the way that the JDK NamingManager classes operate. This explains both the different line numbers in the NamingManager and why
        
        at org.apache.aries.jndi.OSGiInitialContextFactoryBuilder.getInitialContext(OSGiInitialContextFactoryBuilder.java:46)
        
        appears in the stack trace.

        Without the jndi-1.0 feature applications are unable to access server configured resources via JNDI (we will inject them using @Resource annotations, but they wont be in JNDI).

        Jacek I hope that helps to explain your problem, although it still doesn't answer the previous question.

        Thanks
        Alasdair
        • Jacek_Laskowski
          Jacek_Laskowski
          133 Posts
          ACCEPTED ANSWER

          Re: Failed to create datasource jndi reference at Spring and Liberty profile

          ‏2012-12-06T12:34:50Z  in response to SystemAdmin
          Hi Alasdair,

          Thanks.

          I think I was slightly misled after reading your answer in which it was assumed no jndi feature was enabled. I however learnt a lot and am very grateful for your detailed response.

          Jacek
          Japila :: verba docent, exempla trahunt
    • SystemAdmin
      SystemAdmin
      590 Posts
      ACCEPTED ANSWER

      Re: Failed to create datasource jndi reference at Spring and Liberty profile

      ‏2012-12-06T02:36:35Z  in response to SystemAdmin
      I enabled jndi feature at server.xml.

      <featureManager>
      <feature>jsp-2.2</feature>
      <feature>jndi-1.0</feature>
      <feature>jdbc-4.0</feature>
      </featureManager>
      • SystemAdmin
        SystemAdmin
        590 Posts
        ACCEPTED ANSWER

        Re: Failed to create datasource jndi reference at Spring and Liberty profile

        ‏2012-12-06T20:22:34Z  in response to SystemAdmin
        Hi,

        I believe you are hitting a known APAR (PM70625 [1]). The fix to this problem is available to customers who have purchased support for WebSphere Application Server. I believe based on your profile you work for a company that has purchased support so I suggest you follow the normal processes to raise a PMR [2] and request an iFix.

        Thanks
        Alasdair
        [1] http://www-01.ibm.com/support/docview.wss?uid=swg1PM70625
        [2] https://www-947.ibm.com/support/servicerequest/Home.action
    • SystemAdmin
      SystemAdmin
      590 Posts
      ACCEPTED ANSWER

      Re: Failed to create datasource jndi reference at Spring and Liberty profile

      ‏2012-12-06T02:49:24Z  in response to SystemAdmin
      I have enabled jndi feature at server.xml before creating datasource, We successfully accessing jndientry for properties loading like below.
      <jndiEntry jndiName="abc/envPath" value="D:\\Liberty\\config\\abcvvvv.properties" />

      But not able to access datasource realted jndi entries.

      Please help us to resolve the issue.

      Thanks in Advance.