AnsweredAssumed Answered

activity - get service registry in java class

Question asked by dmralfing on Mar 20, 2014
Latest reply on Mar 26, 2014 by dmralfing
Somebody could tell me what I´m doing wrong to get the service registry in the java class, or
well any way to get it? - I have tryed using the solution I read in the forum topic :
..but I´m afraid I´m doing something wrong due to I´m a beginer in activity, so I would apreciate if somebody help me..
This is the Java code:

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="" xmlns:xsi="" xmlns:activiti="" xmlns:bpmndi="" xmlns:omgdc="" xmlns:omgdi="" typeLanguage="" expressionLanguage="" targetNamespace="Examples">
  <process id="MyTest" name="MyTest">
   <startEvent id="theStart" name="Start">
    <serviceTask id="javaService" name="Java service invocation" activiti:class="org.activiti.examples.bpmn.test.manager2.SetterTest">
        <activiti:field name="text">
        <activiti:taskListener event="create" class="org.activiti.examples.bpmn.test.manager2.SetterTest">
   <userTask id="usertask1" name="User Task" activiti:candidateGroups="user"></userTask>
   <endEvent id="theEnd" name="End"></endEvent>
    <sequenceFlow id="flow1" name="" sourceRef="theStart" targetRef="javaService"></sequenceFlow>
    <sequenceFlow id="flow2" name="" sourceRef="javaService" targetRef="usertask1"></sequenceFlow>   
    <sequenceFlow id="flow4" name="" sourceRef="usertask1" targetRef="theEnd"></sequenceFlow>

..and this is my class that unaffortunately doesn´t get the serviceRegistry..

package org.activiti.examples.bpmn.test.manager2;
import …
public class SetterTest implements JavaDelegate {

   private static final String VARIABLE_NAME = "testVariable";
   private Expression text;
   ServiceRegistry serviceRegistry=null;
   //public ServiceRegistry getServiceRegistry() {return serviceRegistry;}
   protected ServiceRegistry getServiceRegistry() {

        ProcessEngineConfigurationImpl config = Context.getProcessEngineConfiguration();
        if (config != null) {
            ServiceRegistry registry = (ServiceRegistry) config.getBeans().get(ActivitiConstants.SERVICE_REGISTRY_BEAN_KEY);
            if (registry == null) {
                throw new RuntimeException(
                            "Service-registry not present in ProcessEngineConfiguration beans, expected ServiceRegistry with key" +
               System.out.println("————— config =null");
            return registry;

        throw new IllegalStateException("No ProcessEngineCOnfiguration found in active context");

   public void setServiceRegistry(ServiceRegistry serviceRegistry) {this.serviceRegistry = serviceRegistry;}
   public void execute(DelegateExecution execution)
         if (serviceRegistry==null)
            System.out.println("serviceRegistry is null!!");

Thank you so much!