无法启动使用 Cloud SDK 库调用 Workflow Rest API 的应用程序

Failed to start application invoking Workflow Rest API with Cloud SDK libraries

我正在按照官方文档使用 Cloud SDK 库调用工作流 REST API。

https://sap.github.io/cloud-sdk/docs/java/features/rest/clients/scp-workflow-rest-api

当我将应用程序部署到 Cloud Foundry 环境时。它无法启动。我在本地启动应用程序时,错误消息是一样的。

云SDK版本:3.27.0

下面是错误堆栈。

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[=11=](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

源代码

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;
    }

}

==============更新============================ ===================

我缩小了这个问题的根本原因。

我使用 cloud sdk 原型创建了一个新项目并添加了工作流依赖项。

<dependency>
    <groupId>com.sap.cloud.sdk.services</groupId>
    <artifactId>scp-workflow-cf</artifactId>
</dependency>

应用程序将因上述错误而失败。

更新:SAP Cloud SDK 3.28.1 从今天开始可用并修复了这个问题。 查看发行说明 here.

感谢您报告这个 Jerry。这是一个错误,一旦 SAP Cloud SDK 发布错误修复,我将在此处更新此答案。

作为解决方法,您可以使用 SAP Cloud SDK scp-cf-tomee 的 Tomee 原型。那里不存在这个问题。