8 Replies Latest reply on Oct 26, 2011 10:59 PM by lakemove

    Spring JBpm 4.3 loading a custom IdentitySession

    newbeewan

      Hi,

       

      I'm trying to integrate spring and Jbpm.

       

      I'm  using the SpringHelper to start the processEngine :

      {code}<?xml  version="1.0" encoding="UTF-8"?>

       

      <jbpm-configuration>


           <import resource="jbpm.tx.spring.cfg.xml" />
          <import  resource="jbpm.jpdl.cfg.xml" />

       

          <import  resource="jbpm.businesscalendar.cfg.xml" />
          <import  resource="jbpm.console.cfg.xml" />
          <import  resource="jbpm.jobexecutor.cfg.xml" />
         
           <script-manager default-expression-language="juel"
               default-script-language="juel"
              read-contexts="execution,  environment, process-engine, spring"
              write-context="">
               <script-language name="juel"
                   factory="org.jbpm.pvm.internal.script.JuelScriptEngineFactory" />
           </script-manager>
         
          <transaction-context>
               <object/>
           </transaction-context>
          <hibernate-session  current="true" />
      </jbpm-configuration>{/code}

       

      My  identitySession is loaded by spring (I have done a Junit test to  validate !).

       

      JBPM doesn't seem to search for beans in  the spring context.

      I've got that exception :

      {code}

      Caused  by: org.springframework.beans.factory.BeanCreationException: Could not  autowire field: private org.jbpm.api.ProcessEngine  my.package.bpm.service.LdapIdentitySessionTest.processEngine; nested  exception is org.springframework.beans.factory.BeanCreationException:  Error creating bean with name 'processEngine' defined in class path  resource [my/package/service/jbpmConfigurationTest.xml]: Instantiation  of bean failed; nested exception is  org.springframework.beans.factory.BeanDefinitionStoreException: Factory  method [protected org.jbpm.api.ProcessEngine  org.jbpm.pvm.internal.processengine.SpringHelper.createProcessEngine()]  threw exception; nested exception is org.jbpm.api.JbpmException:
         error: parsing exception: couldn't load class 'identitySession' :  org.jbpm.pvm.internal.wire.WireException: couldn't load class  'identitySession'
           at  org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:507)
           at  org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:84)
           at  org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:283)
           ... 26 more
      Caused by: org.springframework.beans.factory.BeanCreationException:  Error creating bean with name 'processEngine' defined in class path  resource [my/package/service/jbpmConfigurationTest.xml]: Instantiation  of bean failed; nested exception is  org.springframework.beans.factory.BeanDefinitionStoreException: Factory  method [protected org.jbpm.api.ProcessEngine  org.jbpm.pvm.internal.processengine.SpringHelper.createProcessEngine()]  threw exception; nested exception is org.jbpm.api.JbpmException:
         error: parsing exception: couldn't load class 'identitySession' :  org.jbpm.pvm.internal.wire.WireException: couldn't load class  'identitySession'
           at  org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:568)
           at  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:973)
           at  org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:879)
           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:190)
           at  org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:827)
           at  org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:769)
           at  org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:686)
           at  org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
           ... 28 more

      {/code}

       

      What is the right configuration to force  jbpm to solve objects in spring context ?

       

      Regards

        • 1. Re: Spring JBpm 4.3 loading a custom IdentitySession
          sebastian.s

          AFAIK you have to replace jBPM's ObjectFactory by a Factory using the SpringContext to resolve object names. I know you are using jBPM 4.x but maybe you find some inspiration on how to make jBPM use a SpringObjectFactory in this tutorial for jBPM 3.2:

           

          http://www.jorambarrez.be/blog/2009/04/17/integrating-jbpm3-with-spring-part1/

           

          With respect to the tutorial you would need to create a SpringObjectFactory (implementating jBPM's ObjectFactory) and instantiate the factory via Spring. Then pass the ObjectFactory into the Configuration bean.

          • 2. Re: Spring JBpm 4.3 loading a custom IdentitySession
            rebody

            Hi Jaber,

              There is something missing in your configuration.  It must be caused by the Web Editor.  So I cannot see how you configure custom identity session.  Could you upload an attach?  Thank you.

            • 3. Re: Spring JBpm 4.3 loading a custom IdentitySession
              newbeewan

              No pb, it is in attachment.

               

              I put also the spring config in attachment, but my beans are mainly configure by annotation.

               

              Regards

              • 4. Re: Spring JBpm 4.3 loading a custom IdentitySession
                rebody

                Hi Jaber,

                  I think you could try

                 

                <object expr="#{identitySession}"/>
                
                • 5. Re: Spring JBpm 4.3 loading a custom IdentitySession
                  newbeewan

                  Many thanks, that's it !

                   

                  But I have an NPE, I think it is somthing wrong in my conf :

                   

                  2010-04-30 10:58:56,521 [INFO ]  org.jbpm.pvm.internal.svc.DefaultCommandService  - exception while  executing command  org.jbpm.pvm.internal.jobexecutor.AcquireJobsCmd@4a0ce796
                  java.lang.NullPointerException
                        at  org.jbpm.pvm.internal.jobexecutor.AcquireJobsCmd.execute(AcquireJobsCmd.java:91)
                        at  org.jbpm.pvm.internal.jobexecutor.AcquireJobsCmd.execute(AcquireJobsCmd.java:41)
                        at  org.jbpm.pvm.internal.svc.DefaultCommandService.execute(DefaultCommandService.java:42)
                        at  org.jbpm.pvm.internal.tx.SpringCommandCallback.doInTransaction(SpringCommandCallback.java:45)
                        at  org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:130)
                        at  org.jbpm.pvm.internal.tx.SpringTransactionInterceptor.execute(SpringTransactionInterceptor.java:55)
                        at  org.jbpm.pvm.internal.svc.EnvironmentInterceptor.executeInNewEnvironment(EnvironmentInterceptor.java:53)
                        at  org.jbpm.pvm.internal.svc.EnvironmentInterceptor.execute(EnvironmentInterceptor.java:40)
                        at  org.jbpm.pvm.internal.svc.RetryInterceptor.execute(RetryInterceptor.java:55)
                        at  org.jbpm.pvm.internal.jobexecutor.DispatcherThread.acquireJobs(DispatcherThread.java:126)
                        at  org.jbpm.pvm.internal.jobexecutor.DispatcherThread.run(DispatcherThread.java:67)
                  2010-04-30   10:58:56,523 [INFO ]  org.jbpm.pvm.internal.jobexecutor.DispatcherThread  - DispatcherThread  leaves cyberspace
                  Exception in thread "DispatcherThread"  java.lang.NullPointerException
                      at  org.jbpm.pvm.internal.jobexecutor.DispatcherThread.run(DispatcherThread.java:96)
                  
                  
                  

                  And the identityService is null

                   

                  Regards

                  • 6. Re: Spring JBpm 4.3 loading a custom IdentitySession
                    newbeewan

                    Nevermind, I found the solution...

                     

                    I missed the default configuration file (jbpm.default.cfg.xml) !

                     

                    it works well now

                    • 7. Re: Spring JBpm 4.3 loading a custom IdentitySession
                      dhamaris

                      How did you do to avoid the IdentityService null?

                       

                      I've been struggling with that for weeks, I'm using jbpm 4.4 and have the default configuration, that is:

                       

                      <?xml version="1.0" encoding="UTF-8"?>

                       

                       

                      <jbpm-configuration>

                       

                       

                                <!-- <import resource="jbpm.default.cfg.xml" /> -->

                                <import resource="jbpm.tx.spring.cfg.xml" />

                                <import resource="jbpm.jpdl.cfg.xml" />

                                <import resource="jbpm.identity.cfg.xml" />

                                <import resource="jbpm.businesscalendar.cfg.xml" />

                                <import resource="jbpm.console.cfg.xml" />

                                <import resource="jbpm.jobexecutor.cfg.xml" />

                       

                                <script-manager default-expression-language="juel"

                                          default-script-language="juel"

                                          read-contexts="execution, environment, process-engine, spring"

                                          write-context="">

                                          <script-language name="juel"

                                                    factory="org.jbpm.pvm.internal.script.JuelScriptEngineFactory" />

                                </script-manager>

                       

                                <transaction-context>

                                          <object class="identitySession" />

                                </transaction-context>

                                <hibernate-session current="true" />

                      </jbpm-configuration>

                       

                      I tried to initialize identityService adding it as a bean in applicationContext-process file, like this:

                       

                       

                      <bean id="identityService" factory-bean="processEngine" factory-method="getIdentityService" />

                       

                      Any ideas?

                      Thanks

                       

                      Dámaris.

                      • 8. Re: Spring JBpm 4.3 loading a custom IdentitySession
                        lakemove

                        hi Dámaris

                         

                        use EL "#{identitySession}"

                         

                         

                        {code:xml}

                        <!-- replace identity config with spring managed bean -->

                        <!-- <import resource="jbpm.identity.cfg.xml" /> -->

                        <transaction-context>

                          <object expr="#{identitySession}" />

                        </transaction-context>

                        {code}