cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing annotated spring beans in an expression

ikazarno
Champ in-the-making
Champ in-the-making
Hi,

today is a first day I’m experimenting with activiti. It seems to be a nice framework, thanks guys Smiley Happy

I have a problem accessing an annotated spring bean in a service task expression:

<serviceTask id="servicetask" name="Service Task" activiti:expression="#{myService.performAction()}"></serviceTask>

My service bean looks as follows:

@Service("myService")
public class MyServiceImpl implements Serializable {
  public void performAction() {
    // some business logic
  }
}

My Unit Test Code:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({"classpath:test-config.xml"})
public class MyWorkflowTest {

   @Autowired
   @Rule
   public ActivitiRule activitiSpringRule;

   @Test
   public void testMyProcess() {
      RuntimeService runtimeService = activitiSpringRule.getRuntimeService();
      runtimeService.startProcessInstanceByKey("myProcess");
   }
}

If I execute the test I get following error:
org.activiti.engine.ActivitiException: Unknown method used in expression: #{myService.performAction()}
Caused by: org.activiti.engine.impl.javax.el.MethodNotFoundException: Cannot find method perform with 0 parameters in class com.sun.proxy.$Proxy25
   at org.activiti.engine.impl.javax.el.BeanELResolver.invoke(BeanELResolver.java:476)
   at org.activiti.engine.impl.javax.el.CompositeELResolver.invoke(CompositeELResolver.java:397)

If I put the bean in the spring config, it works! Can I use the annotated beans, without defining them in the spring config?

Thanks in advance!
Igor
2 REPLIES 2

bathe
Champ in-the-making
Champ in-the-making
I guess, you need to use $ instead of # in EL expressions.   I mean try  ${myService.performAction()}  instead of #{myService.performAction()}

ikazarno
Champ in-the-making
Champ in-the-making
It would be great if the problem could be solved so easy. But according to the user guide you can use # in expressions…

I think the problem is due to the fact that org.activiti.engine.impl.javax.el.BeanELResolver gets a proxy instead of a real object from the spring context evaluating the expression. The question now is whether there is a solution for this problem that allows me to use my annotated beans or I have to define all my spring beans in a XML configuration file.