I want to inject field values to Camunda delegate. Because it's more convenient to have separate inputs for every listener (here - java classes), but not for them all, working within this activity. (it is even more important for such technical and through task like logging – which we want not to be visible, but doing its work)
My delegate is a Spring bean, cause i want to autowire loggingRestService
to it.
As Spring bean is a Singleton by default, for renewing injected fields' values (so, we can say, the delegate become statefull because of these inputs from a BPMN process) i use SCOPE_PROTOTYPE and it works as i wish:
@Service
@Scope(SCOPE_PROTOTYPE)
class BusinessLogDelegate : JavaDelegate {
private val loggingRestService: LoggingRestService
override fun execute(execution: DelegateExecution) {...}
}
But in the Camunda docs there is no info about such solution, only restriction not to use Spring/CDI beans:
For the same reasons as mentioned above, field injection should not be (usually) used with Spring beans, which are singletons by default. Otherwise, you may run into inconsistencies due to concurrent modification of the bean fields.
As written in Is Spring's @Autowired a huge performance issue? the most expensive operation is creating of a bean (not an injection), but without being bean, java class instance will be created every time when it called by Camunda bpm. So there is no addition lack of performance.
Are there any other problems in this solution?