title: Annotation based Spring Activiti ProcessEngine
body: <p>I am quite new to Spring and Activiti. I'm developing annotation based Spring web application with embedded Activiti engine. I have some services implemented, SubscriptionService is one of them. In one process I call that service as bean with:</p>
  
  <pre><code>activiti:expression="${subscriptionService.getContacts(publisherCode, contactType)}"
  </code></pre>
  
  <p>Service:</p>
  
  <pre><code>@Service
  @Transactional
  public class DBSubscriptionService implements SubscriptionService {
  ...
  }
  </code></pre>
  
  <p>I have separated test module and web module. Test module loads context from activiti.cfg.xml with</p>
  
  <pre><code>@ContextConfiguration("classpath:activiti.cfg.xml")
  </code></pre>
  
  <p>and it is:</p>
  
  <pre><code>&lt;bean id="processEngineConfiguration"
      class="org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration"&gt;
      &lt;property name="databaseType" value="h2" /&gt;
      &lt;property name="databaseSchemaUpdate" value="true" /&gt;
      &lt;property name="jobExecutorActivate" value="false" /&gt;
      &lt;property name="history" value="full" /&gt;
      &lt;property name="mailServerPort" value="2025" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean"&gt;
      &lt;property name="processEngineConfiguration" ref="processEngineConfiguration" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="repositoryService" factory-bean="processEngine"
      factory-method="getRepositoryService" /&gt;
  &lt;bean id="runtimeService" factory-bean="processEngine"
      factory-method="getRuntimeService" /&gt;
  &lt;bean id="taskService" factory-bean="processEngine"
      factory-method="getTaskService" /&gt;
  &lt;bean id="historyService" factory-bean="processEngine"
      factory-method="getHistoryService" /&gt;
  &lt;bean id="managementService" factory-bean="processEngine"
      factory-method="getManagementService" /&gt;
  &lt;bean id="identityService" factory-bean="processEngine"
      factory-method="getIdentityService" /&gt;
  &lt;bean id="formService" factory-bean="processEngine"
      factory-method="getFormService" /&gt;
  
  &lt;context:component-scan base-package="cz.muni.fi.cep" /&gt;
  &lt;context:annotation-config /&gt;
  </code></pre>
  
  <p>In test module, everything works fine. But in web module when it should call subscriptionService Bean it throws:</p>
  
  <pre><code>    Unknown property used in expression: ${subscriptionService.getContacts(publisherCode, contactType)}
  Caused by: org.activiti.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier 'subscriptionService'
      at org.activiti.engine.impl.juel.AstIdentifier.eval(AstIdentifier.java:83)
      at org.activiti.engine.impl.juel.AstMethod.invoke(AstMethod.java:79)
      at org.activiti.engine.impl.juel.AstMethod.eval(AstMethod.java:75)
      at org.activiti.engine.impl.juel.AstEval.eval(AstEval.java:50)
      at org.activiti.engine.impl.juel.AstNode.getValue(AstNode.java:26)
      at org.activiti.engine.impl.juel.TreeValueExpression.getValue(TreeValueExpression.java:114)
      at org.activiti.engine.impl.delegate.ExpressionGetInvocation.invoke(ExpressionGetInvocation.java:33)
      at org.activiti.engine.impl.delegate.DelegateInvocation.proceed(DelegateInvocation.java:37)
      at org.activiti.engine.impl.delegate.DefaultDelegateInterceptor.handleInvocation(DefaultDelegateInterceptor.java:25)
      at org.activiti.engine.impl.el.JuelExpression.getValue(JuelExpression.java:48)
      ... 363 more
  </code></pre>
  
  <p>So I understand problem is that Process engine does not use right application context, because subscription service is autowired to other classes just fine. But I don't know how to fix it.</p>
  
  <p>Web module is purely annotation based:</p>
  
  <pre><code>@EnableAutoConfiguration
  @Configuration
  @EntityScan(basePackages = "cz.muni.fi.cep")
  @ComponentScan(basePackages = "cz.muni.fi.cep")
  public class App extends WebMvcConfigurerAdapter {
  
      public static void main(String[] args) {
          SpringApplication.run(App.class, args);
      }
  
      ...
  } 
  </code></pre>
  
  <p>And Activiti configuration:</p>
  
  <pre><code>@Configuration
  public class ActivitiConfig {
  
      @Bean
      public ProcessEngine processEngine(ProcessEngineConfigurationImpl pec, ApplicationContext applicationContext) throws Exception {
          ProcessEngineFactoryBean pe = new ProcessEngineFactoryBean();
          pe.setProcessEngineConfiguration(pec);
          pe.setApplicationContext(applicationContext);
  
          return pe.getObject();
      }
  
      @Bean
      public ProcessEngineConfigurationImpl getProcessEngineConfiguration(
              DataSource dataSource,
              PlatformTransactionManager transactionManager,
              ApplicationContext context) {
          SpringProcessEngineConfiguration pec = new SpringProcessEngineConfiguration();
  
          pec.setDataSource(dataSource);
          pec.setDatabaseSchemaUpdate("true");
          pec.setJobExecutorActivate(true);
          pec.setHistory("full");
          pec.setMailServerPort(2025);
          pec.setDatabaseType("mysql");
  
          pec.setTransactionManager(transactionManager);
          pec.setApplicationContext(context);
  
          return pec;
      }
  
      @Bean
      public RuntimeService getRuntimeService(ProcessEngine processEngine) {
          return processEngine.getRuntimeService();
      }
  ...
  }
  </code></pre>
  
  <p>Also, maybe order of context creation has somethong to do with this.</p>