I am following the official documentation to call workflow REST APIs with Cloud SDK libraries.
https://sap.github.io/cloud-sdk/docs/java/features/rest/clients/scp-workflow-rest-api
When I deployed the application to Cloud Foundry environment. It failed to start. The error messages are the same when I started the application locally.
Cloud SDK version: 3.27.0
Below is the error stack.
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-08-28 13:46:44.052 ERROR 23576 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.sap.cloud.sdk.services.scp.workflow.cf.api.WorkflowInstancesApi' defined in URL [jar:file:/C:/Apache/maven3.6/repository_new/com/sap/cloud/sdk/services/scp-workflow-cf/3.27.0/scp-workflow-cf-3.27.0.jar!/com/sap/cloud/sdk/services/scp/workflow/cf/api/WorkflowInstancesApi.class]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.sap.cloud.sdk.services.scp.workflow.cf.api.WorkflowInstancesApi]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.sap.cloud.sdk.services.scp.workflow.cf.api.WorkflowInstancesApi.<init>()
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1320)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1214)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517)
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:323)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:321)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:895)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:878)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:143)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:758)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1237)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226)
at com.boshch.workflow.WorkflowApplication.main(WorkflowApplication.java:23)
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.sap.cloud.sdk.services.scp.workflow.cf.api.WorkflowInstancesApi]: No default constructor found; nested exception is java.lang.NoSuchMethodException: com.sap.cloud.sdk.services.scp.workflow.cf.api.WorkflowInstancesApi.<init>()
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:83)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1312)
... 18 common frames omitted
Caused by: java.lang.NoSuchMethodException: com.sap.cloud.sdk.services.scp.workflow.cf.api.WorkflowInstancesApi.<init>()
at java.lang.Class.getConstructor0(Class.java:3082)
at java.lang.Class.getDeclaredConstructor(Class.java:2178)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:78)
... 19 common frames omitted
Souce code
import java.util.List;
import org.springframework.stereotype.Service;
import com.boshch.workflow.service.WorkflowDefinitionsService;
import com.sap.cloud.sdk.cloudplatform.connectivity.DestinationAccessor;
import com.sap.cloud.sdk.cloudplatform.connectivity.HttpDestination;
import com.sap.cloud.sdk.services.scp.workflow.cf.api.WorkflowDefinitionsApi;
import com.sap.cloud.sdk.services.scp.workflow.cf.model.WorkflowDefinition;
@Service
public class WorkflowDefinitionServiceImp implements WorkflowDefinitionsService {
private static final HttpDestination WF_DESTINATION = DestinationAccessor
.getDestination("my-workflow-instance")
.asHttp();
@Override
public List<WorkflowDefinition> getWorkflowDefinitions() {
List<WorkflowDefinition> wfDefinitions = new WorkflowDefinitionsApi(WF_DESTINATION).queryDefinitions();
return wfDefinitions;
}
}
==============Update=================================================
I narrowed down the root cause of this issue.
I created a fresh project with cloud sdk archetype and added workflow dependency.
<dependency>
<groupId>com.sap.cloud.sdk.services</groupId>
<artifactId>scp-workflow-cf</artifactId>
</dependency>
The application would fail with above error.
mvn spring-boot:run
and then it fails already? Meaning you did not add any source code? If my understanding is incomplete, please state the precise procedure in the question. – Emdee