AnsweredAssumed Answered

Problem with Spring autowiring within a Service Task

Question asked by gaston on Nov 18, 2012
Latest reply on Jul 23, 2013 by wsalembi
Hi all,
I'm having problems calling a Spring autowired Repository from a task. The idea is to have the Service Task call one of the methods of a Service. Problem is, after executing the service task, I'm getting an "Unknown property in expression" if using a delegateExpression (similar to what's mentioned in this other thread), or a null pointer exception, as a result of the @Autowired Repository in myService not being properly instantiated).

The Service Task is being run as

My service bean is as follows:

   public class MyBeanServiceImpl implements JavaDelegate {

      private TestServiceDummy serviceDummy;

      public void execute(DelegateExecution execution) { User()); // <– NPE here, the userRepository is null when called. ie: not being properly autowired.

   // Getters and Setters for the testServiceDummy omitted for brevity


Here's my TestServiceDummyImpl:

   @Transactional(readOnly = true)
   public class TestServiceDummyImpl implements TestServiceDymmy {
      private UserRepository userRepository;
      public User save(User user) {;
      // Getters && Setters for the repository

And a simple JPARepository from SpringData

   public interface UserRepository extends JPARepository<User, Long> {
The same thing works without problems when called from our webapp (calling the service as a @ManagedProperty works ok) so the embedded project's config seems to be ok.

And here's Activiti Explorer's applicationContext file:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns=""


   <context:property-placeholder location="classpath*" />

   <!– Scan this classpath for annotated components that will be auto-registered
      as Spring beans –>
   <context:annotation-config />

   <!– scan the embedded project's components –>
        <context:component-scan base-package="edu.bedelias.*" />

   <jpa:repositories base-package="edu.bedelias.repositories*" />

      class="" />

   <!– Automatically translate hibernate/jpa exceptions into Spring's generic
      DataAccessException hierarchy for those classes annotated with Repository –>
      class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

   <!– JPA Entity Manager Factory –>
   <bean id="entityManagerFactory"
      <property name="dataSource" ref="dataSource" />
      <property name="jpaVendorAdapter" ref="hibernateJpaVendorAdapter" />
      <property name="packagesToScan">
      <property name="jpaProperties">
            <!– set HibernateJpaVendorAdapter's behavior: 'create' = build a new
               DB on each run; 'update' = modify an existing database; 'create-drop' = 'create'
               and also drops tables when Hibernate closes; 'validate' = makes no changes
               to the database –>
            <prop key="">create-drop</prop>

   <bean id="hibernateJpaVendorAdapter"
      <property name="showSql" value="true" />
      <property name="generateDdl" value="false" />
      <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />

   <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
      <property name="driverClass" value="${jdbc.driverClass}" />
      <property name="jdbcUrl" value="${jdbc.jdbcUrl}" />
      <property name="user" value="${jdbc.user}" />
      <property name="password" value="${jdbc.password}" />
      <property name="maxPoolSize" value="${jdbc.maxPoolSize}" />
      <property name="maxStatements" value="${jdbc.maxStatements}" />
      <property name="minPoolSize" value="${jdbc.minPoolSize}" />

   <!– Transaction Manager is defined –>
   <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
      <property name="entityManagerFactory" ref="entityManagerFactory" />
      <property name="dataSource" ref="dataSource" />

   <!– Hijack the current @Session scope annotation on each @Service and make
      it last only for the duration of the thread –>
   <bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
      <property name="scopes">
            <entry key="session">
               <bean class="" />

   <!– Enable the configuration of transactional behavior based on annotations –>
   <tx:annotation-driven />

   <bean id="dbProperties"
      <property name="location" value="" />
      <!– Allow other PropertyPlaceholderConfigurer to run as well –>
      <property name="ignoreUnresolvablePlaceholders" value="true" />

   <bean id="demoDataGenerator" class="org.activiti.explorer.demo.DemoDataGenerator">
      <property name="processEngine" ref="processEngine" />

   <bean id="processEngineConfiguration" class="org.activiti.spring.SpringProcessEngineConfiguration">
      <property name="dataSource" ref="dataSource" />
      <property name="transactionManager" ref="transactionManager" />
      <property name="databaseSchemaUpdate" value="true" />
      <property name="jobExecutorActivate" value="true" />
      <property name="customFormTypes">
            <ref bean="userFormType" />

   <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean"
      <property name="processEngineConfiguration" ref="processEngineConfiguration" />

   <bean id="repositoryService" factory-bean="processEngine"
      factory-method="getRepositoryService" />
   <bean id="runtimeService" factory-bean="processEngine"
      factory-method="getRuntimeService" />
   <bean id="taskService" factory-bean="processEngine"
      factory-method="getTaskService" />
   <bean id="historyService" factory-bean="processEngine"
      factory-method="getHistoryService" />
   <bean id="managementService" factory-bean="processEngine"
      factory-method="getManagementService" />
   <bean id="identityService" factory-bean="processEngine"
      factory-method="getIdentityService" />

   <bean id="activitiLoginHandler" class="org.activiti.explorer.ui.login.DefaultLoginHandler">
      <property name="identityService" ref="identityService" />

   <!– Include the UI-related wiring. This UI context will be used in the
      alfresco activiti admin UI –>
   <import resource="activiti-ui-context.xml" />

   <!– Custom form types –>
   <bean id="userFormType" class="org.activiti.explorer.form.UserFormType" />


I've tried going for an "Expression" approach, as suggested [url=
]here and here to no avail.

If anyone is curious, the URL of the project is here:

Thanks in advance,