[jboss-user] [jBPM] - Accessing Spring Beans within process definition

Miroslav Štencel do-not-reply at jboss.com
Thu Apr 21 11:34:15 EDT 2011


Miroslav Štencel [http://community.jboss.org/people/mstencel] created the discussion

"Accessing Spring Beans within process definition"

To view the discussion, visit: http://community.jboss.org/message/601479#601479

--------------------------------------------------------------
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.
--------------------------------------------------------------

Reply to this message by going to Community
[http://community.jboss.org/message/601479#601479]

Start a new discussion in jBPM at Community
[http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2034]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110421/1f19686a/attachment.html 


More information about the jboss-user mailing list