How to initilize JavaDelegate with some properties from a properties file?

Hello.

I have a custom JavaDelegate that I would like to initialize with some custom properties from a properties file.
Can you please give me some information on how to achieve that?

Using the application.properties files would be good enough.

Thank you.

  @Value("${spring.security.oauth2.resourceserver.jwt.jwk-set-uri}")
  private String jwkSetUri;

See: Properties with Spring and Spring Boot

Thank you.

I am going to try it tomorrow.

Hello.

I have tried this, but it is not working.
Simply adding the @Value annotation gave me a null value.

Is it required to annotate the class with something or maybe create any kind of xml file to register this JavaDelegate?

I tried including the @Component into this class, but nothing changed.

Thank you again.

Something I haven’t mentioned.

I’m trying to reuse the application.properties file, located at the /lib folder for this.

I have tried lots of options I found in my research, but nothing seems to work.

This should work:

@Component
public class ServiceClassDelegateSample implements JavaDelegate {
    @Autowired
    private SampleService sampleService;

    @Value("${property.test}")
    private String prop;

    @Override
    public void execute(DelegateExecution delegateExecution) throws Exception {
        sampleService.doSomething();
    }
}

<serviceTask id="serviceTask" flowable:delegateExpression="${serviceClassDelegateSample}"></serviceTask>

Thank you for the answer.

I have tried with this approach also, and it didin’t work.

My class is now annotated with the @Component annotation, and I changed the service task to use the delegate expression instead of the class name.
The problem now is that flowable is not able to use it.

My class name is CreatePGCService, and because of that, I believe the right bean name would be createPGCService.

Changing that, when I execute the proccees and it reaches the service task step, it fails with this:

org.flowable.common.engine.api.FlowableException: Unknown property used in expression: ${createPGCService}

I have my class deployed into the flowable-task/WEB-INF/lib folder.

Maybe it’s because of the path?
Should I deploy it somewhere else?

Hey, here’s another shot:

@Component("customServiceBean")
public class CreatePGCService implements JavaDelegate {
    @Autowired
    private SampleService sampleService;

    @Value("${property.test}")
    private String prop;

    @Override
    public void execute(DelegateExecution delegateExecution) throws Exception {
        sampleService.doSomething();
    }
}

<serviceTask id="serviceTask" flowable:delegateExpression="${customServiceBean}"></serviceTask>

I have tried that also, and not luck with it.

Right now I am trying by deploying my custom jar into tomcat/lib, but as soon as I tried that, I started to get other errors for flowable classes not found, and then I am giving another try by copying the jar files where such classes are defined.

I will update the thread with the results.

Thank you for your time anyway.

Yes, it didn’t work.

The error message continues:
Caused by: java.lang.ClassNotFoundException: org.flowable.task.service.delegate.TaskListener

How come?

As a last try, I have moved my jar and copied the applications.properties file both inside flowable-task/WEB-INF/lib folder, and even with that, the bean is not resolved using the delegate expression.
After that, I changed the process to use the class name instead, and then the java code is executed, but again, the string property I need is not read.

I don’t know what else to try… there must be something really really wrong with my environment, tomcat and all, or I am doing something really stupid.

BTW, the tomcat version I am using is 8.0.53, but I guess that is not important at all.

Ok, I have “solved” my problem by implementing an utility class that reads the properties file and then I am using it to read the properties I need inside my JavaDelegate class.

And for the servicetask configuration, I am using the class name, as that is the only way I was able to make it work.

Thanks for clarification of your solution.

However, the example I gave works in cases of having a Spring Boot Flowable Engine modules in your own, external application.

1 Like