创建ErpConfigContext引发异常 [英] Creating ErpConfigContext threw exception

查看:122
本文介绍了创建ErpConfigContext引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to use the S/4HANA SDK to call the CompanyCode OData VDM service but if I do this in the Cloud Foundry environment I'm getting the attached error. I have been using the SDK before but this did not happened. Can you please help me here?

代码:

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

推荐答案

您可以尝试确保在应用程序中选择了RequestContextServletFilter吗? RequestContextServletFilter默认使用@WebFilter批注.

Can you try to make sure that the RequestContextServletFilter is picked up in your application? The RequestContextServletFilter uses the @WebFilter annotation by default.

Spring Boot示例:

Example for 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

请注意,在后台作业中运行代码(不是由请求触发)时,必须使用

Note that when running your code in a background job (not triggered by a request), you have to wrap your code with RequestContextExecutor::execute.

这篇关于创建ErpConfigContext引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆