Service Task expression + Spring Boot

771 views
Skip to first unread message

Markus Hens

unread,
Nov 27, 2015, 12:31:37 PM11/27/15
to camunda BPM users
Hi,

I try to call a spring bean from a service task but always get an exception that bean was not found:

 Unknown property used in expression: ${carServiceImpl.repair(carId)}. Cause: Cannot resolve identifier 'carServiceImpl'


Car Service is defined as a spring bean. Im able to autowire it or access it directly via application context (applicationContext.getBean("carServiceImpl").


I use in a spring boot (1.3.0) environment. 


My problem is, that I do not understand how camunda gets beans from application context to resolve the JUEL expression.


Any documentation for that? Or any idea why my simple service call cant`t find my bean in spring boot context?


Best regards,


Markus



Markus Hens

unread,
Nov 27, 2015, 2:40:35 PM11/27/15
to camunda BPM users
P.S: 

When I explicitly set beans on processEngineConfiguration via setBeans(Map<Object,Object> beans) method, they are accessable for my service task but I thought if 
I would not call this method all beans of the appContext are accessable by default as described in the documentation.

Philipp Ossler

unread,
Nov 30, 2015, 2:55:59 AM11/30/15
to camunda BPM users
Hi Markus,

please read the documentation [1] first.
If your process still don't work then provide a failing test case [2] and I will look at it.

Greetings,
Philipp

Christian Lipphardt

unread,
Nov 30, 2015, 6:45:03 AM11/30/15
to camunda BPM users
Hi Markus,

Could you please post your Spring Java Config regarding the initialization of the Process Engine.

Cheers,
Christian

Markus Hens

unread,
Dec 1, 2015, 3:22:58 AM12/1/15
to camunda BPM users

       @Bean(name="taskService")


        public TaskService taskService(ProcessEngine processEngine) {


        return processEngine.getTaskService();


    }


       


        @Bean(name="repositoryService")


        public RepositoryService repositoryService(ProcessEngine processEngine) {


        return processEngine.getRepositoryService();


    }


       


        @Bean(name="runtimeService")


        public RuntimeService runtimeService(ProcessEngine processEngine) {


        return processEngine.getRuntimeService();


    }


       


        @Bean(name="historyService")


        public HistoryService historyService(ProcessEngine processEngine) {


        return processEngine.getHistoryService();


    }


       


        @Bean(name="managementService")


        public ManagementService managementService(ProcessEngine processEngine) {


        return processEngine.getManagementService();


    }




        @Bean(name="caseService")


        public CaseService caseService (ProcessEngine processEngine) {


        return processEngine.getCaseService();


    }


       


        @Bean


        public SpringProcessEngineConfiguration processEngineConfiguration(PlatformTransactionManager tm, ApplicationContext appContext) throws IOException{


                SpringProcessEngineConfiguration conf = new SpringProcessEngineConfiguration();


                conf.setDataSource(dataSource());


                conf.setDatabaseSchemaUpdate("true");


                conf.setTransactionManager(tm);


                conf.setHistory("full");


                conf.setJobExecutorActivate(true);


               


                PathMatchingResourcePatternResolver resourceResolver = new PathMatchingResourcePatternResolver();


                conf.setDeploymentResources(resourceResolver.getResources("processes/*.bpmn20.xml"));          


               


                //No Beans available if Iuncomment this


                //List<String> relevantBeans = Arrays.asList(appContext.getBeanNamesForAnnotation(Service.class));

         


                //Map<Object, Object> beans = relevantBeans.stream()


                           //     .collect(Collectors.toMap((beanName) -> beanName, (beanName) -> appContext.getBean(beanName)));



              //  conf.setBeans(beans);


               


                return conf;


        }




        @Bean(name="processEngine")


        public ProcessEngine processEngine(SpringProcessEngineConfiguration processEngineConfiguration) throws Exception {


                ProcessEngineFactoryBean pef = new ProcessEngineFactoryBean();


                pef.setProcessEngineConfiguration(processEngineConfiguration);


                return pef.getObject();


    }


Hi Chritian,

see my configuration of process engine above. If this does not help I can send you a failing testcase of course.

Best regards,

Markus

Philipp Ossler

unread,
Dec 2, 2015, 4:31:14 AM12/2/15
to camunda BPM users
Hi Markus,

thank's for your config. I can reproduce your problem.There is one tricky issue in your config. The bean with name "processEngine" must return the factory bean instead of the process engine.

@Bean(name = "processEngine")
public ProcessEngineFactoryBean processEngine(SpringProcessEngineConfiguration processEngineConfiguration) throws Exception {
  ProcessEngineFactoryBean pef = new ProcessEngineFactoryBean();
  pef.setProcessEngineConfiguration(processEngineConfiguration);
  return pef;
}

It is the same as in the XML config [1]. The reason is caused by spring that have to inject the application context into the factory bean since it implements the interface ApplicationContextAware.

We will add an example on the documentation how to work with Java Config.

Greetings,
Philipp

Markus Hens

unread,
Dec 2, 2015, 5:09:36 AM12/2/15
to camunda BPM users
Hi Phillip,

my mistake. Your explanation and your solution works fine for me. Maybe a bit documentation about JavaConfig in your guide would help.

Thanks a lo for your effort.

Best regards,

Markus

Am Freitag, 27. November 2015 18:31:37 UTC+1 schrieb Markus Hens:

Philipp Ossler

unread,
Jan 7, 2016, 6:50:45 AM1/7/16
to camunda BPM users
Reply all
Reply to author
Forward
0 new messages