Configuration problem: Unable to locate Spring NamespaceHandler for XM

One Star

Configuration problem: Unable to locate Spring NamespaceHandler for XM

After I added the code in bold at the Spring, I got the above error.
<?xml version="1.0" encoding="UTF-8"?>
<!--Used to inject external resources, beans or define more CamelContext and RouteBuilder here-->
<beans xmlns=""
       xmlns:xsi=""
       xmlns:camel=""
       xmlns:context=""
       xmlnsSmiley Surprisedsgi=""
       xsi:schemaLocation="
           
           
 
            ">
    <bean id="jmxEventNotifier" class="org.apache.camel.management.JmxNotificationEventNotifier" >
        <property name="source" value="DemoDatasource" />
        <property name="ignoreCamelContextEvents" value="true" />
        <property name="ignoreRouteEvents" value="true" />
        <property name="ignoreServiceEvents" value="true" />
        <property name="ignoreExchangeEvents" value="true" />
    </bean>
    <osgi:reference id="demoDS" interface="javax.sql.DataSource" filter="(osgi.jndi.service.name=jdb-TRNG)"/>
</beans>
Anyone have any idea how to fix it?
Thanks,
email3888
Employee

Re: Configuration problem: Unable to locate Spring NamespaceHandler for XM

Hi,
The namespace handler for Spring-DM is defined in the spring-osgi-core/1.2.1 jar, it could not be loaded automatically when you add osgi:reference into the Spring xml in the Studio, that's why you got the "Unable to locate Spring NamespaceHandler ...".
If you want to reference a DataSource using Spring-DM, you have to export/publish the Route into Talend Runtime (OSGi container), the Runtime container has the spring-osgi-core/1.2.1 and its dependences pre-installed. also you need to deploy the DataSource "demoDS" before deploy the Route.
(you may add a cConfig component and add spring-osgi-core-1.2.1.jar into it from Studio to solve the "Unable to locate Spring NamespaceHandler ...", but it's not the expected way for Spring-DM use case)
Regards.
One Star

Re: Configuration problem: Unable to locate Spring NamespaceHandler for XM

Thanks xldai! I added the cConfig and passed thru that error. I got another error. Is it related to the version of the jar?
Unexpected exception parsing XML document from class path resource ; nested exception is org.springframework.beans.FatalBeanException: Invalid NamespaceHandler class for namespace []: problem with handler class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org/osgi/framework/ServiceReference
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from class path resource ; nested exception is org.springframework.beans.FatalBeanException: Invalid NamespaceHandler class for namespace []: problem with handler class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org/osgi/framework/ServiceReference
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:413)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:335)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:174)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:127)
at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:93)
at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130)
at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:539)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:451)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at demo_project.demodatasource_0_1.DemoDatasource$2.createContext(DemoDatasource.java:204)
at org.apache.camel.main.Main.getCamelContextMap(Main.java:148)
at org.apache.camel.main.MainSupport.postProcessContext(MainSupport.java:386)
at org.apache.camel.main.Main.doStart(Main.java:124)
at org.apache.camel.support.ServiceSupport.start(ServiceSupport.java:61)
at org.apache.camel.main.MainSupport.run(MainSupport.java:124)
at demo_project.demodatasource_0_1.DemoDatasource.run(DemoDatasource.java:270)
at demo_project.demodatasource_0_1.DemoDatasource.runJobInTOS(DemoDatasource.java:332)
at demo_project.demodatasource_0_1.DemoDatasource.main(DemoDatasource.java:302)
Caused by: org.springframework.beans.FatalBeanException: Invalid NamespaceHandler class for namespace []: problem with handler class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org/osgi/framework/ServiceReference
at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.resolve(DefaultNamespaceHandlerResolver.java:139)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1427)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1422)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:187)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:147)
at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:101)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:495)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:391)
... 22 more
Caused by: java.lang.NoClassDefFoundError: org/osgi/framework/ServiceReference
at org.springframework.osgi.config.CollectionBeanDefinitionParser.<clinit>(CollectionBeanDefinitionParser.java:78)
at org.springframework.osgi.config.OsgiNamespaceHandler.init(OsgiNamespaceHandler.java:40)
at org.springframework.beans.factory.xml.DefaultNamespaceHandlerResolver.resolve(DefaultNamespaceHandlerResolver.java:130)
... 29 more
Caused by: java.lang.ClassNotFoundException: org.osgi.framework.ServiceReference
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 32 more
One Star

Re: Configuration problem: Unable to locate Spring NamespaceHandler for XM

Hi xldai,
I added more jars in cConfig as in the screenshot. My current error is 
Error creating bean with name 'trngDS': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Required 'bundleContext' property was not set. Can you help me to solve it?

Thanks in advanced!
email3888
Employee

Re: Configuration problem: Unable to locate Spring NamespaceHandler for XM

Hi
Well, are you expected running the Route within Studio? What I suggested is based on the DataSource is deployed in Runtime, also the Route is running in the Runtime container.
I've never tried the Route + DataSource running in Studio, if you want to try you don't need to introduce the osgi:reference , you can define the DataSource bean in the same spring.
Regards.
One Star

Re: Configuration problem: Unable to locate Spring NamespaceHandler for XM

Hi xldai,
I am not expected to run in Studio, but at least there is no compilation error. I think there will be runtime error (at least for the datasource)
I tried to deploy to Karaf. I got this error.
karaf@trun()> feature:install TestDatasource-feature
ERROR org.apache.karaf.shell.support.ShellUtil - Exception caught while executing command
org.osgi.service.resolver.ResolutionException: 
Unable to resolve root: missing requirement
  osgi.identity; osgi.identity=TestDatasource-feature; type=karaf.feature; version=""; filter:="(&(osgi.identity=TestDatasource-feature)(type=karaf.feature)(version>=0.1.0)(version<=0.1.0))" osgi.identity; osgi.identity=demo_project.TestDatasource; type=osgi.bundle; version=""; resolution:=mandatory osgi.wiring.package; filter:="(osgi.wiring.package=org.osgi)"]]
Thanks very much for looking into it.
email3888
Employee

Re: Configuration problem: Unable to locate Spring NamespaceHandler for XM

Hi,
OK. if you expect running the Route in Runtime container, you need to "Build Route"/"Publish" it, that will be no any compilation error from Studio. the compilation error you mentioned only happening when you try to "Run" the route within Studio. So please remove the cConfig component or remove the spring-osgi-core, org.osgi.core lib from the cConfig then "Build Route"/"Publish" it.
We are not sure if Route + Datasource (your use case) is fully supported. as alternative suggestion, you may create a Job using tXXXConnection (e.g tMySQLConnection) and "Specify a data source alias", and invoke this Job using cTalendJob component in your Route.
Regards.
One Star

Re: Configuration problem: Unable to locate Spring NamespaceHandler for XM

Hi xldai,
I removed the cConfig and export it to karaf. I still got the same error.
Unable to resolve root: missing requirement
Thanks for suggesting to use Job, instead of Route. But, our company has some Camel projects which want to migrate into Talend and we want to keep the technology. This is my proof of concept project. I was following the link below to do it. Can you tell me what is missing in karaf or the kar?

Thanks again!
email3888
One Star

Re: Configuration problem: Unable to locate Spring NamespaceHandler for XM

I uploaded the simple project with 3 components. Can you see if it works on your system?
Thanks,
email3888
DemoDatasource.zip.zip