11 Replies Latest reply on Nov 12, 2009 9:08 PM by njiang

    ClassNotFoundException related to bean creation

    rinerc

      I am running into a problem when I try to deploy a Camel to FUSE ESB.  When an attempt is made to create the bean, I am getting the following error:

       

      smx@root:/> Exception in thread "SpringOsgiExtenderThread-86" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'camelContext:beanPostProcessor': Cannot resolve reference to bean 'camelContext' while setting bean property 'camelContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'camelContext': Invocation of init method failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class for bean with name 'hl7codec' defined in URL bundle://182.0:0/META-INF/spring/beans.xml; nested exception is java.lang.ClassNotFoundException: org.apache.camel.component.hl7.HL7MLLPCodec not found from bundle

       

      The bean I am trying to create is set up in the following way:

       

      <bean id="hl7codec" class="org.apache.camel.component.hl7.HL7MLLPCodec">

                <property name="charset" value="iso-8859-1"/>

      </bean>

       

      I am at a loss as to why this error is occurring?  If anyone has any ideas, I would greatly appreciate it.

       

      Thanks,

       

      Robert Rine

       

        • 1. Re: ClassNotFoundException related to bean creation
          oisin

          Robert - have you got the hl7 component installed in the OSGi container? It's probably meant to be added as a separate bundle.

           

          By the way, the error message is really hard to read, mangled by the forum software.

           

          Putting the string  before and after the error text will help make it more legible.

          • 2. Re: ClassNotFoundException related to bean creation
            rinerc

            I have attempted to install the camel-hl7 component, but I'm not convinced I have done it correctly.  I installed it using the following command:

             

            osgi/install file:///opt/progress/fuse-mediation-router-1.6.1.2/lib/camel-hl7-1.6.1.2-fuse.jar
            

             

            This appears to have succeeded, yielding the following in the osgi/list output;

             

            [ 184] [Installed  ] [       ] [   60] camel-hl7 (1.6.1.fuse)
            

             

            I notice that it is in "Installed" state, while other components (like camel-mina) are in "Active" state.

             

            I'm not sure if this is necessary, but i attempted to start the camel-hl7 component using the following command:

             

            osgi/start 184
            

             

            This yields the following error:

             

            ERROR CommandLineExecutionFailed: org.apache.geronimo.gshell.command.CommandException: org.osgi.framework.BundleException: Unresolved constraint in bundle 184: package; (package=ca.uhn.hl7v2.parser)
            

             

            The package ca.uhn.hl7v2.parser is part of the HAPI library.

             

            I can't help but feel I'm doing something incorrectly here.

             

            Thanks,

             

            Robert Rine

            • 3. Re: ClassNotFoundException related to bean creation
              njiang

              Why don't you try to use the features?

              In Fuse ESB , you just need to type "features/install camel-hl7",  you will get camel-hl7 and third party bundles which it depends on installed.

               

              BTW, There are the HAPI library OSGi bundles in the SMX bundle repository.

              • 4. Re: ClassNotFoundException related to bean creation
                rinerc

                The command "features/install camel-hl7" does not work properly.  It generates an error indicating that "No feature named 'camel-hl7' with version '0.0.0' available".  I either do not have the right repository URL's set up in servicemix, or it has something to do with the version of FUSE ESB I'm running (4.1.0.0).  Any ideas will be greatly appreciated.

                 

                Thanks,

                 

                Robert Rine

                • 5. Re: ClassNotFoundException related to bean creation
                  oisin

                  this article is a bit weirdly out of line with the rest, check the date and time on it for where it belongs in the sequence!

                   

                   

                  In Fuse ESB , you just need to type "features/install camel-hl7", you will get camel-hl7 and third party bundles which it depends on installed.

                   

                   

                  This will only work if there's a feature defined for camel-hl7. Out of the box, there isn't (at least in the 4.1.0.2 version of the ESB, which I just happened to try it on).

                  • 6. Re: ClassNotFoundException related to bean creation
                    oisin

                    Hi Robert,

                    This features/install business only works if there is a feature defined somewhere and a URL for it. In this case, there isn't. At this point, I would go ahead and find the bundles I need, and then create the feature.

                     

                    Finding the bundles can be a pain, so I've gone off and done that   I have only tested  that the bundles start, not that they are doing the right thing at runtime. The next step would be to create an ESB feature for these bundles, which will make life easier for future use.

                     

                    Start up the ESB, and go into the OSGi shell -

                    smx@root:> osgi
                    smx@root:osgi>
                    

                     

                    First up - install HAPI

                    smx@root:osgi>install http://repo2.maven.org/maven2/org/apache/servicemix/bundles/org.apache.servicemix.bundles.hapi/0.5.1_3/org.apache.servicemix.bundles.hapi-0.5.1_3.jar
                    Bundle ID: 158
                    

                     

                    HAPI is not happy without some XML parser stuff

                    smx@root:osgi> install http://repo2.maven.org/maven2/org/apache/servicemix/bundles/org.apache.servicemix.bundles.xerces/2.9.1_3/org.apache.servicemix.bundles.xerces-2.9.1_3.jar
                    Bundle ID: 159
                    

                     

                    It also needs a bit of Xpath

                    smx@root:osgi> install http://repo2.maven.org/maven2/org/apache/servicemix/bundles/org.apache.servicemix.bundles.xalan/2.7.1_2/org.apache.servicemix.bundles.xalan-2.7.1_2.jar
                    Bundle ID: 160
                    

                     

                    In turn, Xalan needs a bit of BCEL

                    smx@root:osgi> install http://repo2.maven.org/maven2/org/apache/servicemix/bundles/org.apache.servicemix.bundles.bcel/5.2_2/org.apache.servicemix.bundles.bcel-5.2_2.jar
                    Bundle ID: 161
                    

                     

                    And, finally, HAPI is still looking for something, in this case JDOM

                    smx@root:osgi> install http://repo2.maven.org/maven2/org/apache/servicemix/bundles/org.apache.servicemix.bundles.jdom/1.1_2/org.apache.servicemix.bundles.jdom-1.1_2.jar       
                    Bundle ID: 162
                    

                     

                    The constraint resolution should be good now and you can start all these bundles to get things going.

                     

                    smx@root:osgi> start 162
                    smx@root:osgi> start 161
                    smx@root:osgi> start 160
                    smx@root:osgi> start 159
                    smx@root:osgi> start 158
                    smx@root:osgi> list
                    ...irrelevant bundles display removed...
                    [ 158] [Active     ] [       ] [   60] Apache ServiceMix Bundles: hapi-0.5.1 (0.5.1.3)
                    [ 159] [Active     ] [       ] [   60] Apache ServiceMix Bundles: xercesImpl-2.9.1 (2.9.1.3)
                    [ 160] [Active     ] [       ] [   60] Apache ServiceMix Bundles: xalan-2.7.1 (2.7.1.2)
                    [ 161] [Active     ] [       ] [   60] Apache ServiceMix Bundles: bcel-5.2 (5.2.0.2)
                    [ 162] [Active     ] [       ] [   60] Apache ServiceMix Bundles: jdom-1.1 (1.1.0.2)
                    

                     

                    • 7. Re: ClassNotFoundException related to bean creation
                      rinerc

                      Thank you for the help.  I performed all the steps you outlined, and installed the camel-hl7 the way I originally had it.  I was able to set up a simple XML route the provided an HL& listener and wrote the message to a directory (shown below):

                       

                      <?xml version="1.0" encoding="UTF-8"?>
                      <beans xmlns="http://www.springframework.org/schema/beans"
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      xmlns:camel-osgi="http://activemq.apache.org/camel/schema/osgi"
                      xsi:schemaLocation="
                      http://www.springframework.org/schema/beans
                      http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
                      http://activemq.apache.org/camel/schema/spring
                      http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
                      http://activemq.apache.org/camel/schema/osgi
                      http://activemq.apache.org/camel/schema/osgi/camel-osgi.xsd">
                      
                      <bean id="hl7codec" class="org.apache.camel.component.hl7.HL7MLLPCodec">
                        <property name="charset" value="iso-8859-1"></property>
                      </bean>
                      
                      <camel-osgi:camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
                      
                        <route>
                          <from uri="mina:tcp://localhost:28888?sync=true&amp;codec=hl7codec"></from>
                          <to uri="file:///tmp/camel-hl7-test-out"></to>
                        </route>
                      
                      </camel-osgi:camelContext>
                      </beans>
                      

                       

                      This worked, but my experiment with maven is still resulting in the same error:

                       

                      Exception in thread "SpringOsgiExtenderThread-74" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'camelContext:beanPostProcessor': Cannot resolve reference to bean 'camelContext' while setting bean property 'camelContext'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'camelContext': Invocation of init method failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.apache.camel.component.hl7.HL7MLLPCodec] for bean with name 'hl7codec' defined in URL [bundle://191.0:0/META-INF/spring/beans.xml]; nested exception is java.lang.ClassNotFoundException: org.apache.camel.component.hl7.HL7MLLPCodec not found from bundle [camel-jms-example]
                              at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:275)
                              at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:104)
                              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1245)
                              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1010)
                              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:472)
                              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory$1.run(AbstractAutowireCapableBeanFactory.java:409)
                              at java.security.AccessController.doPrivileged(Native Method)
                              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:380)
                              at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:264)
                              at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
                              at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:261)
                              at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:185)
                              at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:164)
                              at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:880)
                              at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.registerBeanPostProcessors(AbstractDelegatedExecutionApplicationContext.java:547)
                              at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.registerBeanPostProcessors(AbstractDelegatedExecutionApplicationContext.java:482)
                              at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext$4.run(AbstractDelegatedExecutionApplicationContext.java:324)
                              at org.springframework.osgi.util.internal.PrivilegedUtils.executeWithCustomTCCL(PrivilegedUtils.java:85)
                              at org.springframework.osgi.context.support.AbstractDelegatedExecutionApplicationContext.completeRefresh(AbstractDelegatedExecutionApplicationContext.java:308)
                              at org.springframework.osgi.extender.internal.dependencies.startup.DependencyWaiterApplicationContextExecutor$CompleteRefreshTask.run(DependencyWaiterApplicationContextExecutor.java:138)
                              at java.lang.Thread.run(Thread.java:619)
                      ...
                      

                       

                      I must be missing something simple, because all the pieces appear to be in place from a Servicemix standpoint.

                       

                      Thanks,

                       

                      Robert Rine

                      • 8. Re: ClassNotFoundException related to bean creation
                        oisin

                        I'm checking the HL7 component page here for reference, but one thing I noticed on the MINA component page was that if you are using Camel 2.0, you need to change the syntax to use the # sign to refer to the bean -

                        <from uri="mina:tcp://localhost:28888?sync=true&amp;#codec=hl7codec"/>
                        

                         

                        But on looking at this again, I'd say the issue is that the camel-hl7 component is the one that is missing. We have HAPI, which is used by the camel-hl7 component, but do we have the camel-hl7 component itself in the container? Look for a bundle called camel-hl7-x.x.x.x.jar or something like that in the container - it is the one that contains that class that is adjudged missing by Spring.

                        • 9. Re: ClassNotFoundException related to bean creation
                          njiang

                          Hi,

                           

                          It looks like the SpringDM can't find the class of org.apache.camel.component.hl7.HL7MLLPCodec.

                           

                          Did you import the package org.apache.camel.component.hl7 in your application bundle ? If not , please add it.

                           

                          Willem

                          • 10. Re: ClassNotFoundException related to bean creation
                            njiang

                            I just check the features list in the Fuse ESB 4.1.0.2, there is no feature for camel-hl7.  You can walk around it by adding the blow lines into the file  $ESB-HOME/system/org/apache/servicemix/camel/org.apache.servicemix.camel.features/4.1.0.2-fuse/org.apache.servicemix.camel.features-4.1.0.2-fuse-features.xml

                             

                            <feature name='camel-hl7' version='1.6.1.0-fuse'>
                                <feature version='1.6.1.0-fuse'>camel-core</feature>
                                <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.xerces/2.9.1_3</bundle>
                                <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jdom/1.1_2</bundle>
                                <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.hapi/0.5.1_3</bundle>
                                <bundle>mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.mina/1.1.7_3</bundle>
                                <bundle>mvn:org.apache.camel/camel-hl7/1.6.1.0-fuse</bundle>
                              </feature>
                            

                             

                            • 11. Re: ClassNotFoundException related to bean creation
                              rinerc

                              Importing the package into the bundle solved the remaining problem.  I appreciate everyone's help on this issue.

                               

                              Thanks,

                               

                              Robert Rine