0 Replies Latest reply on Apr 21, 2011 11:37 AM by mstencel

    Accessing Spring Beans within process definition

    mstencel Newbie

      Are there any solution how to access Spring beans in process definition directly? The goal is to access custom beans in actions or other properties  without any need to map them implicitly for each process instance.

      I tried one solution overriding default global resolver with a kind of Spring based, that searches an identifier in the Spring Context. Then every Spring bean id that is used should be declared as global within the rulebase.

       

       

      {code}

      import org.drools.base.MapGlobalResolver;

      import org.springframework.context.ApplicationContext;

       

      public class SpringGlobalResolver extends MapGlobalResolver {

       

          private ApplicationContext ctx;

       

          public SpringGlobalResolver(ApplicationContext ctx)

          {

              this.ctx=ctx;

          }

       

          @Override

          public Object resolveGlobal(String identifier) {

       

              if ( ctx!=null && ctx.containsBean(identifier))

                  return ctx.getBean(identifier);

       

              return super.resolveGlobal(identifier);

          }

       

      }

      {code}

       

       

       

      And then I registered it to knowledge session by putting to environment map:

       

      {code}

      env.set(EnvironmentName.GLOBALS,

                new SpringGlobalResolver(ctx));

      {code}

       

       

      Is this the correct approach or is there another solution? Maybe Spring beans could be exposed and access as parameters e.g.

      {noformat}#{beanId.method()}{noformat}

      And I suppose they shouldn't be persisted.