I like the the ability to use constructors to add dependencies. Especially autowiring those dependencies.
e.g.
public class MyClass {
private final Dependency dependency;
@Autowired
public MyClass(@Qualifier("bean-id") Dependency dependency) {
this.dependency = dependency;
}
}
What I'm finding is that the Spring Cloud AWS framework throws an "InstantiationException" if the "Dependency" class above happens to be a class which is passed to a Workflow worker and is missing a default, empty constructor.
concrete example:
public class MyClass {
private final DependencyWorkflowClientExternalFactory clientFactory;
@Autowired
public MyClass(@Qualifier("bean-id") DependencyWorkflowClientExternalFactory clientFactory) {
this.clientFactory = clientFactory;
}
}
public class WorkflowInitializer {
@Autowired
private WorkflowWorker workflowWorker; //assume wired with correct credentials
public WorkflowInitialiser() {
init();
}
public init() {
workflowWorker.addWorkflowImplementationType(MyClass.class);
}
}
the above fails with:
java.lang.InstantiationException: com.mypackage.MyClass
at java.lang.Class.newInstance(Class.java:359)
I have to do something like:
public class MyClass {
@Autowired
@Qualifier("bean-id")
private Dependency dependency;
public MyClass() {
}
}
The question is:
Is it possible in the current release of the Spring Cloud framework to use the @Autowire annotation on a constructor for a workflow client implementation? Or is it a requirement that the annotation is added to the instance field?
As a secondary question:
Why do ActivityWorkers take instances of an object but WorkflowWorkers take classes?
Aucun commentaire:
Enregistrer un commentaire