Not able to use spring bean in service task

cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Member II

Not able to use spring bean in service task

Hello Everyone,

         I want to create custom beans in Alfresco Process Service 1.9, for that i'm following the  Spring Beans | Alfresco Documentation. As per this i have create one java class which is registered as bean and having one method that called in APS service task's expression.

but i got an error while starting process : 

org.activiti.engine.ActivitiException: Unknown property used in expression: ${helloWorldBean.sayHello(execution)}
...
Caused by: org.activiti.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier 'helloWorldBean'
...

It will be really helpful if someone will let me know what kind of configuration is missing. Also just wanted to confirm that I've added my project's exported jar into "/alfresco/process-services-1.9.0/tomcat/webapps/activiti-app/WEB-INF/lib". Correct me if this is not the desired folder path to add the project jar file. 

best regards,

Manish Luste 

1 Reply
Highlighted
Active Member

Re: Not able to use spring bean in service task

If you use JavaConfig, you must use the 'SpringProcessEngineConfiguration' and 'ProcessEngineFactoryBean' classes (creating its as beans). Here is the example:

@PropertySource({"classpath:jdbc.properties"})
@EnableTransactionManagement
@SpringBootApplication
        (
                scanBasePackages = {"ru.core",}
        )
public class Application {

//other beans

  @Bean
    SpringProcessEngineConfiguration getProcessEngineConfiguration(@Qualifier("dataSourceForActiviti") DataSource dataSourceForActiviti,
                                                                   @Qualifier("transactionManagerForActiviti") PlatformTransactionManager transactionManagerForActiviti) {
        SpringProcessEngineConfiguration processEngineConfiguration = new SpringProcessEngineConfiguration();
        processEngineConfiguration.setTransactionManager(transactionManagerForActiviti);

        processEngineConfiguration
                .setDataSource(dataSourceForActiviti)
                .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE)
                .setAsyncExecutorActivate(true);

        processEngineConfiguration.setDeploymentResources(new Resource[]{
                new ClassPathResource("bpm/Process1.bpmn20.xml"),
                new ClassPathResource("bpm/Process2.bpmn20.xml")
        });


        return processEngineConfiguration;
    }

    @Bean
    ProcessEngineFactoryBean getProcessEngineFactoryBean(SpringProcessEngineConfiguration processEngineConfiguration) {
        ProcessEngineFactoryBean processEngineFactoryBean = new ProcessEngineFactoryBean();
        processEngineFactoryBean.setProcessEngineConfiguration(processEngineConfiguration);
        return processEngineFactoryBean;
    }

    @Bean
    RepositoryService getRepositoryService(ProcessEngineFactoryBean processEngineFactoryBean) throws Exception {
        return processEngineFactoryBean.getObject().getRepositoryService();
    }

    @Bean
    RuntimeService getRuntimeService(ProcessEngineFactoryBean processEngineFactoryBean) throws Exception {
        return processEngineFactoryBean.getObject().getRuntimeService();
    }

    @Bean
    TaskService getTaskService(ProcessEngineFactoryBean processEngineFactoryBean) throws Exception {
        return processEngineFactoryBean.getObject().getTaskService();
    }