4

我正在尝试使用 S/4HANA SDK 调用 CompanyCode OData VDM 服务,但如果我在 Cloud Foundry 环境中执行此操作,则会收到附加错误。我之前一直在使用 SDK,但这并没有发生。你能帮帮我吗?

代码:

public List<CompanyCode> findAll() {
    try {
        return compCodeService.getAllCompanyCode().execute(erp())
                .stream()
                .map(this::toCompCode)
                .collect(Collectors.toList());
    } catch (ODataException e) {
        throw SapException.create(e.getMessage());
    }
}

private ErpConfigContext erp(){
    return new ErpConfigContext(REPLICATE_WORKFORCE);
}

 public static final String REPLICATE_WORKFORCE = "REPLICATE_WORKFORCE";

错误:

 [Request processing failed; nested exception is com.sap.cloud.sdk.cloudplatform.tenant.exception.TenantAccessException: Failed to get current tenant: no RequestContext available. Have you correctly configured a RequestContextServletFilter or have you wrapped your logic in a RequestContextExecutor when executing background tasks that are not triggered by a request?] with root cause
    com.sap.cloud.sdk.cloudplatform.tenant.exception.TenantAccessException: Failed to get current tenant: no RequestContext available. Have you correctly configured a RequestContextServletFilter or have you wrapped your logic in a RequestContextExecutor when executing background tasks that are not triggered by a request?
   at com.sap.cloud.sdk.cloudplatform.tenant.AbstractTenantFacade.getCurrentTenantIfAvailable(AbstractTenantFacade.java:85) ~[tenant-2.5.0.jar!/:na]

   at com.sap.cloud.sdk.cloudplatform.tenant.TenantAccessor.getCurrentTenantIfAvailable(TenantAccessor.java:109) ~[tenant-2.5.0.jar!/:na]
   at com.sap.cloud.sdk.cloudplatform.connectivity.ScpCfDestinationFacade.getCacheKey(ScpCfDestinationFacade.java:132) ~[connectivity-scp-cf-2.5.0.jar!/:na]
   at com.sap.cloud.sdk.cloudplatform.connectivity.ScpCfDestinationFacade.getGenericDestinationsByName(ScpCfDestinationFacade.java:178) ~[connectivity-scp-cf-2.5.0.jar!/:na]
   at com.sap.cloud.sdk.cloudplatform.connectivity.AbstractDestinationFacade.getGenericDestination(AbstractDestinationFacade.java:173) ~[com.sap.cloud.s4hana.cloudplatform-connectivity-2.5.0.jar!/:na]
   at com.sap.cloud.sdk.cloudplatform.connectivity.DestinationAccessor.getGenericDestination(DestinationAccessor.java:176) ~[com.sap.cloud.s4hana.cloudplatform-connectivity-2.5.0.jar!/:na]
   at com.sap.cloud.sdk.s4hana.connectivity.ErpConfigContext.(ErpConfigContext.java:218) ~[com.sap.cloud.s4hana-connectivity-2.5.0.jar!/:na]
   at com.sap.cloud.sdk.s4hana.connectivity.ErpConfigContext.(ErpConfigContext.java:367) ~[com.sap.cloud.s4hana-connectivity-2.5.0.jar!/:na]
   at com.sap.cloud.sdk.s4hana.connectivity.ErpConfigContext.(ErpConfigContext.java:442) ~[com.sap.cloud.s4hana-connectivity-2.5.0.jar!/:na]
   at com.sap.csc.employeecreationbe.repository.SdkCompanyCodeRepository.erp(SdkCompanyCodeRepository.java:74) ~[classes/:na]
   at com.sap.csc.employeecreationbe.repository.SdkCompanyCodeRepository.findAll(SdkCompanyCodeRepository.java:64) ~[classes/:na]
   at com.sap.csc.employeecreationbe.repository.SdkCompanyCodeRepository$$FastClassBySpringCGLIB$$f89ad4b4.invoke() ~[classes/:na]
   at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746) ~[spring-aop-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139) ~[spring-tx-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at com.sap.csc.employeecreationbe.repository.SdkCompanyCodeRepository$$EnhancerBySpringCGLIB$$4dd15cde.findAll() ~[classes/:na]
   at com.sap.csc.employeecreationbe.controller.EmployeeController.companyCodes(EmployeeController.java:216) ~[classes/:na]
   at com.sap.csc.employeecreationbe.controller.EmployeeController$$FastClassBySpringCGLIB$$543220b2.invoke() ~[classes/:na]
   at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204) ~[spring-core-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:746) ~[spring-aop-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.8.RELEASE.jar!/:5.0.8.RELEASE]
   at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688) ~[spring-aop-5.0.8.RELEASE.jar!/:5.0.8.RELEASE] and so on
4

1 回答 1

1

您可以尝试确保RequestContextServletFilter在您的应用程序中选择了 吗?默认情况下RequestContextServletFilter使用@WebFilter注解。

Spring Boot 示例:

@SpringBootApplication
@ServletComponentScan( "com.sap.cloud.sdk" )
public class Application extends SpringBootServletInitializer
{
    ...
}

另见:https ://docs.spring.io/spring-boot/docs/current/api/org/springframework/boot/web/servlet/ServletComponentScan.html

编辑:请注意,在后台作业(不是由请求触发)中运行代码时,您必须使用RequestContextExecutor::execute.

于 2018-10-26T09:34:44.690 回答