Custom Connector - Using Spring's dependency injection

Dear community,

How does one go about using Spring’s DI within the implementation of a custom connector?
I have my own extension and I see it picked up by the engine. But since I tried to autowire a bean, I get the NPE at runtime when I try to execute the task.

Do we have to manage our own spring context in our own Connector implementations?

Imagine one tries to re-implement the Mail connectors and wants to read Spring Boot’s mail config as well as reuse other beans from dependencies pulled in.

Hi @paulbors,

I don’t have much insights to the connector implementation, but to use injected services in a delegate you have to wire the delegate as an expression or delegate expression to the process model. Otherwise the injeded object is always null, as there is no context created.

I don’t believe that the connector are wired as expressions in the process.

Hope this helps, Ingo

Hey @Ingo_Richtsmeier,

Sorry, I believe I might have failed to explain myself. I am not trying to pass in a parameter that’s NULL, I am trying to use Spring to implement the connector itself.

How would one be able to use the @Autowired annotation in such a code sample:

import org.camunda.connect.spi.ConnectorProvider;
public class CustomConnectorProviderImpl implements ConnectorProvider {
Engine engine; // How do we get a bean injected inside the Connector impl?
public String getConnectorId() {
    return "custom-connector";

Hope above helps to clarify my question.

Hey @paulbors,

I think that the spring context isn’t available in the connetor out of the box.

As I’m only a spring user but not a spring expert, I don’t know if or how it is possible to extend the spring context form the engine to a custom connector.

I know from my experince that it didn’t work in a delegate class referenced as a Java class in the modeler as well. You have to switch to the delegate expression configuration to extend the spring context to the delegate implementation to use injections in the delegate code.

Hope this helps, Ingo

That clarifies it. We’ll have to do without the Engine Spring context or create a separate one and maintain it ourselves.

Thank you!