Autowired not working in JavaDelegate

Hi,

can anybody guide me on following scenario.

I am trying to do some database operation in javadelegate class for my business logic. I am using spring4 with camunda bpm platform(7.7).

Following is piece of code trying to execute.

@Component
public class DatabaseLookupProcess implements JavaDelegate {

@Autowired
DatabaseLookupService dbLookupServ;

@Override
public void execute(DelegateExecution execution) throws Exception {
	
	dbLookupServ.getLookupData();
}

}

In above code i am getting DatabaseLookupService instance as null whereas this is working in non javadelegate class.
Please suggest how to resolve this issue?

Hi @milindk,
how do you link the class from your BPMN model? Are you using Delegate Expression, as described here: https://docs.camunda.org/get-started/spring/service-task/ ?

I am using delegateclass option and providing qualified classname com.camunda.DatabaseLookupProcess.

This won’t work for version 7.7. But will work in 7.8. See https://app.camunda.com/jira/browse/CAM-7249.

For now try to use Delegate Expression.

Hi Sdorokhova,

Thanks for guiding me. I have tried few option using Delegate Expression but it is not working.

Do you have any reference where some sample examples given on how to autowired using Delegate Expression. Please share me.

hi,

you just have to set the java delegate expression to “#{databaseLookupProcess}”.

2 Likes

Hi @milindk,
I’ve posted you the link to Getting Started. Have you checked it?

https://docs.camunda.org/get-started/spring/service-task/

IMO it illustrates exactly the same as you want to achieve.

You guys are terrific !!!
Thanks Jerome for quick help. My code is working now.

Also works if you annotate JavaDelegate with @Component

1 Like

Adding @Component worked for me, thanks for posting!