11 Replies Latest reply on May 12, 2011 7:48 AM by Alexandre GUYOT

    Howto use jndi ?

    Alexandre GUYOT Newbie

      I try since 1 month to use jndi with datasource (MySQL).

      I made a bundle of DriverMySQL, it work's with sql and jdbc component, but now I would like to use jndi.

       

      src/main/ressources/jndi.properties

      -


      java.naming.factory.initial=org.apache.xbean.spring.jndi.SpringInitialContextFactory

      java.naming.provider.url=jndi.xml

      -


       

      src/main/ressources/jndi.xml

      -


       

      -


       

      src/main/ressources/META-INF/spring/camel-context.xml

      -


       

      -


       

       

       

       

      I have this error :

      -


      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDS': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/core/io/ClassPathResource

      -


       

      And if I put <DynamicImport-Package>*</DynamicImport-Package> in my pom.xml

      -


      org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDS': Invocation of init method failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Unrecognized xbean namespace mapping: http://www.springframework.org/schema/util

      -


       

       

      Please help me, I try many thing without result so I realy need help !

       

      Edited by: maulex on May 10, 2011 1:44 PM

        • 1. Re: Howto use jndi ?
          Freeman(Yue) Fang Master

          Hi,

           

          You need publish your DataSource as OSGi service and use OSGi style jndi name to refer it, take  a look at related discussion[1] to get more details.

           

          http://fusesource.com/forums/thread.jspa?messageID=10525&#10525

          Freeman

          • 2. Re: Howto use jndi ?
            Alexandre GUYOT Newbie

            Hi,

             

            Thanks for your help, but I don't think it's my real problem,  because I have the same error :

            -


            Exception in thread "SpringOsgiExtenderThread-22" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDS': Invocation of init method

            failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/core/io/ClassPathResource

                    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.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)

                    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)

                    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)

                    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)

                    at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)

                    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)

                    at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationC

            ontextExecutor.java:136)

                    at java.lang.Thread.run(Thread.java:662)

            Caused by: java.lang.NoClassDefFoundError: org/springframework/core/io/ClassPathResource

                    at java.lang.Class.forName0(Native Method)

                    at java.lang.Class.forName(Class.java:247)

                    at org.apache.servicemix.naming.OSGiInitialContextFactoryBuilder.createContext(OSGiInitialContextFactoryBuilder.java:156)

                    at org.apache.servicemix.naming.OSGiInitialContextFactoryBuilder.getInitialContext(OSGiInitialContextFactoryBuilder.java:92)

                    at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)

                    at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)

                    at javax.naming.InitialContext.init(InitialContext.java:223)

                    at javax.naming.InitialContext.(InitialContext.java:197)

                    at org.springframework.jndi.JndiTemplate.createInitialContext(JndiTemplate.java:136)

                    at org.springframework.jndi.JndiTemplate.getContext(JndiTemplate.java:103)

                    at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:85)

                    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)

                    ... 14 more

            Caused by: java.lang.ClassNotFoundException: org.springframework.core.io.ClassPathResource

                    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)

                    at java.security.AccessController.doPrivileged(Native Method)

                    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)

                    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)

                    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)

                    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

                    ... 33 more

            -


             

            And with <DynamicImport-Package>...</DynamicImport-Package> in maven-bundle-plugin :

            -


            Exception in thread "SpringOsgiExtenderThread-24" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDS': Invocation of init method

            failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Unrecognized xbean namespace mapping: http://www.springframework.org/schema/o

            sgi

                    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.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)

                    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)

                    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)

                    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)

                    at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)

                    at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)

                    at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationC

            ontextExecutor.java:136)

                    at java.lang.Thread.run(Thread.java:662)

            Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Unrecognized xbean namespace mapping: http://www.springframework.org/schema/osgi

                    at org.apache.xbean.spring.context.v2c.XBeanNamespaceHandler.parseBeanFromExtensionElement(XBeanNamespaceHandler.java:282)

                    at org.apache.xbean.spring.context.v2c.XBeanNamespaceHandler.parse(XBeanNamespaceHandler.java:156)

                    at org.apache.xbean.spring.context.v2.XBeanNamespaceHandler.parse(XBeanNamespaceHandler.java:49)

                    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1335)

                    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1325)

                    at org.apache.xbean.spring.context.v2.XBeanBeanDefinitionDocumentReader.parseBeanDefinitions(XBeanBeanDefinitionDocumentReader.java:84)

                    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:93)

                    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)

                    at org.apache.xbean.spring.context.v2.XBeanXmlBeanDefinitionReader.registerBeanDefinitions(XBeanXmlBeanDefinitionReader.java:79)

                    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)

                    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)

                    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)

                    at org.apache.xbean.spring.context.impl.XBeanXmlBeanFactory.(InitialContext.java:197)

                    at org.springframework.jndi.JndiTemplate.createInitialContext(JndiTemplate.java:136)

                    at org.springframework.jndi.JndiTemplate.getContext(JndiTemplate.java:103)

                    at org.springframework.jndi.JndiTemplate.execute(JndiTemplate.java:85)

                    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)

                    ... 14 more

            -


             

            So my problem is with springframework dependency I think, but how solve my problem? I try many thing without result.

             

            For information :

             

            list | grep Spring

            -


            Spring Core (3.0.5.RELEASE)

            Spring ASM (3.0.5.RELEASE)

            Spring Expression Language (3.0.5.RELEASE)

            Spring Beans (3.0.5.RELEASE)

            Spring AOP (3.0.5.RELEASE)

            Spring Context (3.0.5.RELEASE)

            Spring Context Support (3.0.5.RELEASE)

            Spring Transaction (3.0.5.RELEASE)

            Spring JMS (3.0.5.RELEASE)

            Apache XBean :: Spring (3.7)

            Spring JDBC (3.0.5.RELEASE)

            -


             

            And list | grep spring :

            -


            spring-osgi-io (1.2.0)

            spring-osgi-core (1.2.0)

            spring-osgi-extender (1.2.0)

            spring-osgi-annotation (1.2.0)

            camel-spring (2.6.0.fuse-00-00)

            -


             

            My pom.xml :

            -


             

            <!<DynamicImport-Package>*</DynamicImport-Package>>

            <Import-Package>

            org.apache.camel.osgi,

            *

            </Import-Package>

            <Private-Package>

            com.youhou.test

            </Private-Package>

            </instructions>

            </configuration>

            </plugin>

            </plugins>

            </build>

            </project>

            -


             

             

            Now you have all my projects file and explain to what is wrong into them !

            • 3. Re: Howto use jndi ?
              Freeman(Yue) Fang Master

              Well, I think java.lang.ClassNotFoundException is caused by your customer bundle didn't import necessary package, using Dynamic-Import can fix it but that's not the preferred common way in OSGi world, you should use fine-grained package import instead.

               

              About the Unrecognized xbean namespace mapping, I guess the spring file which cause this error isn't in the src/main/resources/META-INF/spring/ folder, right? You need put spring-dm file in that folder.

               

              Freeman

              • 4. Re: Howto use jndi ?
                Alexandre GUYOT Newbie

                Thanks for your help, you are right it's very important to put jndi.xml into META-INF/spring/ folder.

                 

                So I have move my file, but now I have a new problem, I think than I make a mistake, but I can't find where because I'm a newbie in JNDI.

                 

                This is my new error :

                -


                Exception in thread "SpringOsgiExtenderThread-51" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDS': Invocation of init method

                failed; nested exception is javax.naming.NameNotFoundException: jndiTEST

                        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.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)

                        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)

                        at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)

                        at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)

                        at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)

                        at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)

                        at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationC

                ontextExecutor.java:136)

                        at java.lang.Thread.run(Thread.java:662)

                Caused by: javax.naming.NameNotFoundException: jndiTEST

                        at org.apache.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:167)

                        at org.apache.xbean.naming.context.AbstractContext.lookup(AbstractContext.java:605)

                        at org.apache.servicemix.naming.InitialContextWrapper.lookup(InitialContextWrapper.java:173)

                        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)

                        ... 14 more

                -


                 

                jndi.xml

                -


                 

                -


                 

                camel-context.xml :

                -


                 

                -


                 

                I think than I don't use correctly <jee:jndi-lookup>, but how to use it ?

                 

                When I comment the line <jee:jndi-lookup> and do a osgi:ls on my bundle id :

                -


                TestJNDI (210) provides:

                -


                org.springframework.osgi.bean.name = dsTEST

                Bundle-SymbolicName = TestJNDI

                Bundle-Version = 0.0.1.SNAPSHOT

                osgi.jndi.service.name = jndiTEST

                objectClass = com.mysql.jdbc.jdbc2.optional.MysqlDataSource, javax.sql.DataSource

                service.id = 362

                -


                camel.context.symbolicname = TestJNDI

                camel.context.version = 0.0.1.SNAPSHOT

                objectClass = org.apache.camel.CamelContext

                service.id = 363

                -


                org.springframework.context.service.name = TestJNDI

                Bundle-SymbolicName = TestJNDI

                Bundle-Version = 0.0.1.SNAPSHOT

                objectClass = org.springframework.osgi.context.DelegatedExecutionOsgiBundleApplicationContext, org.springframework.osgi.context.ConfigurableOsgiBundleApplicationContext,

                org.springframework.context.ConfigurableApplicationContext, org.springframework.context.ApplicationContext, org.springframework.context.Lifecycle, org.springframework.bea

                ns.factory.ListableBeanFactory, org.springframework.beans.factory.HierarchicalBeanFactory, org.springframework.context.MessageSource, org.springframework.context.Applicat

                ionEventPublisher, org.springframework.core.io.support.ResourcePatternResolver, org.springframework.beans.factory.BeanFactory, org.springframework.core.io.ResourceLoader,

                org.springframework.beans.factory.DisposableBean

                service.id = 364

                -


                 

                 

                 

                 

                Sorry to ask an help again for this problem ! Thanks a lot !

                • 5. Re: Howto use jndi ?
                  Freeman(Yue) Fang Master

                  Hi,

                  As I mentioned before, you need use OSGi style jndi name

                  Change

                  <jee:jndi-lookup id="myDS" jndi-name="jndiTEST"/>

                  to

                  <jee:jndi-lookup id="myDS" jndi-name="osgi:services/com.mysql.jdbc.jdbc2.optional.MysqlDataSource/(osgi.jndi.service.name = jndiTEST)"/>

                   

                  Freeman

                   

                  Edited by: ffang on May 12, 2011 12:26 AM

                  • 6. Re: Howto use jndi ?
                    Alexandre GUYOT Newbie

                    Thanks for your reply and your help freeman, it's very usefull for me !

                     

                    I try to change my <jee:jndi-lookup> :

                    <jee:jndi-lookup id="myDS" jndi-name="osgi:services/com.mysql.jdbc.jdbc2.optional.MysqlDataSource/(osgi.jndi.service.name=jndiTEST)"/>

                     

                    I try to with javax.sql.DataSource as interface but it doesn't work too ! I have always the same error who says that my service is unavailable :

                    -


                    Exception in thread "SpringOsgiExtenderThread-19" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myDS': Invocation of init method

                    failed; nested exception is javax.naming.NameNotFoundException: (&(objectClass=com.mysql.jdbc.jdbc2.optional.MysqlDataSource)(osgi.jndi.service.name=jndiTEST)) [Root exc

                    eption is javax.naming.ServiceUnavailableException: (&(objectClass=com.mysql.jdbc.jdbc2.optional.MysqlDataSource)(osgi.jndi.service.name=jndiTEST))]

                            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.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563)

                            at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895)

                            at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.access$1600(AbstractDelegatedExecutionApplicationContext.java:69)

                            at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:355)

                            at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)

                            at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:320)

                            at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationC

                    ontextExecutor.java:136)

                            at java.lang.Thread.run(Thread.java:662)

                    Caused by: javax.naming.NameNotFoundException: (&(objectClass=com.mysql.jdbc.jdbc2.optional.MysqlDataSource)(osgi.jndi.service.name=jndiTEST)) [Root exception is javax.na

                    ming.ServiceUnavailableException: (&(objectClass=com.mysql.jdbc.jdbc2.optional.MysqlDataSource)(osgi.jndi.service.name=jndiTEST))]

                            at org.apache.servicemix.naming.OSGiServicesContext.lookup(OSGiServicesContext.java:67)

                            at org.apache.servicemix.naming.OSGiContext.lookup(OSGiContext.java:61)

                            at org.apache.servicemix.naming.InitialContextWrapper.lookup(InitialContextWrapper.java:173)

                            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)

                            ... 14 more

                    Caused by: javax.naming.ServiceUnavailableException: (&(objectClass=com.mysql.jdbc.jdbc2.optional.MysqlDataSource)(osgi.jndi.service.name=jndiTEST))

                            at org.apache.servicemix.naming.ProxyInvocationHandler.getTarget(ProxyInvocationHandler.java:59)

                            at org.apache.servicemix.naming.OSGiServicesContext.lookup(OSGiServicesContext.java:63)

                            ... 27 more

                    -


                     

                    But I can see that all is good when I do a ls on my bundle id :

                    -


                    org.springframework.osgi.bean.name = dsTEST

                    Bundle-SymbolicName = TestJNDI

                    Bundle-Version = 0.0.1.SNAPSHOT

                    osgi.jndi.service.name = jndiTEST

                    objectClass = com.mysql.jdbc.jdbc2.optional.MysqlDataSource, javax.sql.DataSource

                    service.id = 361

                    -


                     

                    Where is the mistake this time ? I can see that all is good when the bundle run, but when I add <jee:jndi-lookup> I have an error, why ?

                     

                    Edited by: maulex on May 12, 2011 8:58 AM

                    • 7. Re: Howto use jndi ?
                      Freeman(Yue) Fang Master

                      Hi,

                       

                      You mean you expose the OSGi service and refer it with JNDI name in same bundle?

                      If so, that's not correct, they should be in different bundles.

                      One bundle to publish the DataSource as OSGi service, other bundles can refer it with correct JNDI name.

                       

                      Freeman

                      • 8. Re: Howto use jndi ?
                        Alexandre GUYOT Newbie

                        You are the best ! It work's !

                         

                        Now I have a few question :

                        - why use osgi:services ? and not util:map with org.apache.xbean.spring.jndi.SpringInitialContextFactory like it's says in Fuse Documentation ??

                        - I understand why make a separate bundle for osgi services, because we can re-use the service from other bundle ! But why it does'nt work when we use it in the same bundle ?

                        - What is the best practise between a separate bundle and use the jndi registry of fuse with the $FUSE_HOME/conf folder ?

                         

                        Thanks again for your help !

                        • 9. Re: Howto use jndi ?
                          Freeman(Yue) Fang Master

                          Hi,

                           

                          I think use the jndi registry of fuse with the $FUSE_HOME/conf folder is suitable for FUSE ESB 3.x, but for FUSE ESB 4.x, it's OSGi container underlying, you should use the OSGi service way to publish it.

                           

                          You can't publish and refer it in same bundle because when spring-dm init the context, it will try to refer a OSGi service which is not get published yet, this is some kind of chicken/egg problem.

                           

                          Hope this helps.

                           

                          Freeman

                          • 10. Re: Howto use jndi ?
                            Alexandre GUYOT Newbie

                            In conclusion we need 3 bundle :

                             

                            Your Bundle who use jndi : <jee:jndi-lookup>

                             

                            Your DriverConnector Bundlized : here it's mySQL Connector with <exported-package> into pom

                             

                            Your OSGI-Services Bundle

                             

                            You can concat and in only one bundle

                             

                            Edited by: maulex on May 12, 2011 11:48 AM

                            • 11. Re: Howto use jndi ?
                              Alexandre GUYOT Newbie

                              Thank you again for your help !