# Associate flowable task with method

**URL:** https://forum.flowable.org/t/associate-flowable-task-with-method/4453
**Category:** Flowable Engine
**Created:** [September 3, 2019, 7:56am UTC](https://forum.flowable.org/t/associate-flowable-task-with-method/4453 "2019-09-03T07:56:57Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![aashi](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@aashi](https://forum.flowable.org/u/aashi)
#### Post date: [September 3, 2019, 7:56am UTC](https://forum.flowable.org/t/associate-flowable-task-with-method/4453/1 "2019-09-03T07:56:57Z")

</div>

Hello Readers,

Until now I’ve known that service task can be associated with a class like below,

And, the class should implement JavaDelegate interface and there should be a method called execute with DelegateExecution as it’s parameter.

Is it possible that I can associate a service task with a simple method like below??

## Service Task:

Class:  
public class HelloWorld {  
private static final Logger LOGGER = Logger.getLogger(HelloWorld.class.getName());  
public void helloWorld(){  
LOGGER.info(“Hello, this is working atleast”);  
}  
}

Regards,  
Ashmita Sinha

---

<div class="post-metadata">

### Author: ![wwitt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wwitt/32/706_2.png) [@wwitt](https://forum.flowable.org/u/wwitt)
#### Post date: [September 3, 2019, 1:50pm UTC](https://forum.flowable.org/t/associate-flowable-task-with-method/4453/2 "2019-09-03T13:50:34Z")

</div>

You can try setting the `expression` on your service task:

[https://flowable.org/docs/userguide/index.html#bpmnJavaServiceTaskXML](https://flowable.org/docs/userguide/index.html#bpmnJavaServiceTaskXML)

---

<div class="post-metadata">

### Author: ![aashi](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@aashi](https://forum.flowable.org/u/aashi)
#### Post date: [September 3, 2019, 7:27pm UTC](https://forum.flowable.org/t/associate-flowable-task-with-method/4453/3 "2019-09-03T19:27:54Z")

</div>

Hello William,

I’ve tried this,

but this gives error: Unknown property used in expression: #{helloWorld.helloWorld()}.

Which means, it is unable to get the bean and call helloWorld(). Is tere anything else which can be done?

Thanks in advance !

Regards,  
Ashmita Sinha

---

<div class="post-metadata">

### Author: ![wwitt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wwitt/32/706_2.png) [@wwitt](https://forum.flowable.org/u/wwitt)
#### Post date: [September 3, 2019, 8:17pm UTC](https://forum.flowable.org/t/associate-flowable-task-with-method/4453/4 "2019-09-03T20:17:06Z")

</div>

@aashi,

Here’s a sample app [https://github.com/unamanic/forum-flowable-expression](https://github.com/unamanic/forum-flowable-expression). I tend to use `$` as opposed to `#`, however either _should_ work. In order to use expression in this way `helloWorld` needs to be registered as a bean.

- The BPMN in the sample I have a service task with `flowable:expression="${demoService.hello()}"`.
- The `DemoService` is as follows:

```java
package com.example.flowableexpression.services;

import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Service;

@Service
@Log4j2
public class DemoService {

    public String hello(){
        log.info("executing DemoService.hello()");
        return "hello";
    }
}

```

---

<div class="post-metadata">

### Author: ![aashi](https://avatars.discourse-cdn.com/v4/letter/a/da6949/32.png) [@aashi](https://forum.flowable.org/u/aashi)
#### Post date: [September 4, 2019, 8:10am UTC](https://forum.flowable.org/t/associate-flowable-task-with-method/4453/5 "2019-09-04T08:10:16Z")

</div>

@wwitt

I tried the github project which you mentioned and that worked fine.

Could you please check [https://github.com/PMD123/Flowable](https://github.com/PMD123/Flowable).

Error which I’m getting: org.flowable.common.engine.impl.javax.el.PropertyNotFoundException: Cannot resolve identifier ‘helloWorld’

---

<div class="post-metadata">

### Author: ![wwitt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wwitt/32/706_2.png) [@wwitt](https://forum.flowable.org/u/wwitt)
#### Post date: [September 4, 2019, 1:03pm UTC](https://forum.flowable.org/t/associate-flowable-task-with-method/4453/6 "2019-09-04T13:03:31Z")

</div>

@akki

I think the biggest complication in your source is that you are manually creating the process engine. I don’t think that the process engine is Spring aware when you create it this way, so it won’t know to inject named beens into the expression handling. This is the same reason that your JavaDelegate has to use `class` instead of `delegateExpression`. There are methods to add additional functions to expression handling [like in ProcessEngineConfigurationImpl](https://github.com/flowable/flowable-engine/blob/master/modules/flowable-engine/src/main/java/org/flowable/engine/impl/cfg/ProcessEngineConfigurationImpl.java) where we initialize the function delegates. But the simplest solution would be to import `flowable-spring` or `flowable-spring-boot-starter` and let the engine find your beans.

Here’s an example project if you don’t want to use the starter:

> **[flowable/flowable-examples](https://github.com/flowable/flowable-examples/tree/master/async-history/async-history-default-cfg)**
>
> Repository with example Flowable projects. Contribute to flowable/flowable-examples development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![wwitt](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/wwitt/32/706_2.png) [@wwitt](https://forum.flowable.org/u/wwitt)
#### Post date: [September 4, 2019, 1:33pm UTC](https://forum.flowable.org/t/associate-flowable-task-with-method/4453/7 "2019-09-04T13:33:14Z")

</div>

> Additionally, it’s possible to register custom functions that can be used in expressions. See the `org.flowable.common.engine.api.delegate.FlowableFunctionDelegate` interface for more information.

> **[Open Source](https://www.flowable.com/open-source)**
>
> The Flowable project provides a core set of open source business process engines that are compact and highly efficient. Get the source code.
