2 Replies Latest reply on Jan 30, 2010 10:54 AM by Alex Malex

    jbpm 4.3 spring & DecisionHandler question

    Alex Malex Newbie
      I use jbpm 4.3 with spring. How can I get spring application context in jbpm decision handler code? As i see jbpm create instance of decision handler not by spring.
        • 1. Re: jbpm 4.3 spring & DecisionHandler question
          Santanu Saraswati Novice

          Unforunately there is no clean way of doing this. You can however use some workaround.

           

          If you remember that good old ServiceLocator J2EE pattern, you can code something similar to locate your spring beans. You can have a class like this:


          import javax.annotation.Resource;

           

          import org.springframework.context.ApplicationContext;
          import org.springframework.stereotype.Component;

           

          /**
          * @author Santanu
          *
          */
          @Component("serviceLocator")
          public class ServiceLocator {
             
              private static ApplicationContext applicationContext;
             
              @Resource
              public void setAplicationContext(ApplicationContext applicationContext) {
                  ServiceLocator.applicationContext = applicationContext;
              }
             
              public static Object getService(String beanName) {
                  return applicationContext.getBean(beanName);
              }
          }

           

          Now in your decision handler can make use of this like this

           

          public class YourDecisionHandler implements DecisionHandler {
             
              private YourSpringBean bean = ServiceLocator.getService("yourBeanName");

              public String decide(OpenExecution execution) {
                  //make use of your bean here
              }
          }

          • 2. Re: jbpm 4.3 spring & DecisionHandler question
            Alex Malex Newbie

            thx for answer! i know about this workaround, but i suppose it isn't so good decision as can be.

            it is strange that jbpm don't provide more better way.