# @Autowired annotation not working when implementing "JavaDelegate" interface

**URL:** <https://forum.flowable.org/t/autowired-annotation-not-working-when-implementing-javadelegate-interface/9369>\
**Category:** Flowable Engine\
**Created:** [May 18, 2022, 1:05pm UTC](https://forum.flowable.org/t/autowired-annotation-not-working-when-implementing-javadelegate-interface/9369 "2022-05-18T13:05:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![sriramb](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@sriramb](https://forum.flowable.org/u/sriramb)\
**Post date:** [May 18, 2022, 1:05pm UTC](https://forum.flowable.org/t/autowired-annotation-not-working-when-implementing-javadelegate-interface/9369/1 "2022-05-18T13:05:29Z")

</div>

Hi All,

I am implementing a listener to send notifications which implements **JavaDelegate** interface. I couldn’t autowire other service classes from this listener class.

Please find my implementation below,

 ![image](https://canada1.discourse-cdn.com/flex035/uploads/flowable/original/2X/1/131b3764464486df3555150d97fe2d5b5e79b95d.png)

Kindly suggest a solution !

Thanks in advance,  
Sriram B

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [May 18, 2022, 1:12pm UTC](https://forum.flowable.org/t/autowired-annotation-not-working-when-implementing-javadelegate-interface/9369/2 "2022-05-18T13:12:31Z")

</div>

You’re trying to autowire to a ServiceTask: that won’t work. A ServiceTask is a modeling element.

You’re probably looking for execution.getCurrentFlowElement() which will give you the current element?

---

<div class="post-metadata">

**Author:** ![sriramb](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@sriramb](https://forum.flowable.org/u/sriramb)\
**Post date:** [May 18, 2022, 1:25pm UTC](https://forum.flowable.org/t/autowired-annotation-not-working-when-implementing-javadelegate-interface/9369/3 "2022-05-18T13:25:36Z")

</div>

Thanks for responding @joram

Its a typo… Actually I am trying to autowire a service class and not the service task… Sorry for the typo.

In my case, i need to access some methods written in other service classes. But i couldn’t autowire those service classes from this listener class.

---

<div class="post-metadata">

**Author:** ![joram](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/joram/32/26_2.png) [@joram](https://forum.flowable.org/u/joram)\
**Post date:** [May 18, 2022, 1:33pm UTC](https://forum.flowable.org/t/autowired-annotation-not-working-when-implementing-javadelegate-interface/9369/4 "2022-05-18T13:33:54Z")

</div>

How are you using this class? If it’s a Spring bean, it should be referenced with a delegateExpression and not through class (otherwise a new object gets created outside of the Spring container).

---

<div class="post-metadata">

**Author:** ![sriramb](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@sriramb](https://forum.flowable.org/u/sriramb)\
**Post date:** [May 19, 2022, 4:12am UTC](https://forum.flowable.org/t/autowired-annotation-not-working-when-implementing-javadelegate-interface/9369/5 "2022-05-19T04:12:54Z")

</div>

Sorry @joram i couldn’t get your question… can you pls detail it out ?

---

<div class="post-metadata">

**Author:** ![amporsim](https://avatars.discourse-cdn.com/v4/letter/a/ea666f/32.png) [@amporsim](https://forum.flowable.org/u/amporsim)\
**Post date:** [May 20, 2022, 9:59am UTC](https://forum.flowable.org/t/autowired-annotation-not-working-when-implementing-javadelegate-interface/9369/6 "2022-05-20T09:59:44Z")

</div>

Hi @sriramb

How do you call the `notificationListener` in your process / case?

Do you use the delegateExpression for it?

```auto
<... delegateExpression="${notificationListener}" ... />

```

---

<div class="post-metadata">

**Author:** ![sriramb](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@sriramb](https://forum.flowable.org/u/sriramb)\
**Post date:** [June 9, 2022, 5:06am UTC](https://forum.flowable.org/t/autowired-annotation-not-working-when-implementing-javadelegate-interface/9369/7 "2022-06-09T05:06:40Z")

</div>

Hi @amporsim

I am not using delegateExpression. I am using listener to call this listener class

---

<div class="post-metadata">

**Author:** ![filiphr](https://yyz1.discourse-cdn.com/flex035/user_avatar/forum.flowable.org/filiphr/32/315_2.png) [@filiphr](https://forum.flowable.org/u/filiphr)\
**Post date:** [August 17, 2022, 10:12am UTC](https://forum.flowable.org/t/autowired-annotation-not-working-when-implementing-javadelegate-interface/9369/8 "2022-08-17T10:12:06Z")

</div>

Hey @sriramb,

In order for `@Autowired` to work you’ll need to expose your class as a bean and use `delegateExpression`. When using `class` Flowable is not going to inject Spring dependencies in your class.

Cheers,  
Filip
