1

我在尝试创建ErpConfigContext. 有谁知道为什么会这样?

代码片段:

 @Bean
public ErpConfigContext erpConfigContext() {
    return new ErpConfigContext("S4HANA_CLOUD");
}

堆栈跟踪:

  *Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.sap.cloud.sdk.s4hana.connectivity.ErpConfigContext]: Factory method 'erpConfigContext' threw exception; nested exception is java.lang.ClassCastException: Cannot cast class com.sap.core.connectivity.apiext.cloud.configuration.CloudConnectivityConfiguration to interface com.sap.core.connectivity.api.configuration.ConnectivityConfiguration
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
    ... 59 common frames omitted*


*Caused by: java.lang.ClassCastException: **Cannot cast class com.sap.core.connectivity.apiext.cloud.configuration.CloudConnectivityConfiguration to interface com.sap.core.connectivity.api.configuration.ConnectivityConfiguration**
    at com.sap.cloud.sdk.cloudplatform.connectivity.ScpNeoDestinationFacade.lookupConnectivityConfiguration(ScpNeoDestinationFacade.java:40)
    at com.sap.cloud.sdk.cloudplatform.connectivity.ScpNeoDestinationFacade.getConnectivityConfiguration(ScpNeoDestinationFacade.java:59)
    at com.sap.cloud.sdk.cloudplatform.connectivity.ScpNeoDestinationFacade.getDestinationConfiguration(ScpNeoDestinationFacade.java:69)
    at com.sap.cloud.sdk.cloudplatform.connectivity.ScpNeoDestinationFacade.getGenericDestination(ScpNeoDestinationFacade.java:105)
    at com.sap.cloud.sdk.cloudplatform.connectivity.DestinationAccessor.getGenericDestination(DestinationAccessor.java:146)
    at com.sap.cloud.sdk.s4hana.connectivity.ErpConfigContext.<init>(ErpConfigContext.java:209)
    at com.sap.cloud.sdk.s4hana.connectivity.ErpConfigContext.<init>(ErpConfigContext.java:355)
    at com.sap.cloud.sdk.s4hana.connectivity.ErpConfigContext.<init>(ErpConfigContext.java:429)
    at com.sap.csc.timebackend.config.S4Beans.erpConfigContext(S4Beans.java:20)
    at com.sap.csc.timebackend.config.S4Beans$$EnhancerBySpringCGLIB$$5076fc70.CGLIB$erpConfigContext$1(<generated>)
    at com.sap.csc.timebackend.config.S4Beans$$EnhancerBySpringCGLIB$$5076fc70$$FastClassBySpringCGLIB$$bc447478.invoke(<generated>)
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
    at com.sap.csc.timebackend.config.S4Beans$$EnhancerBySpringCGLIB$$5076fc70.erpConfigContext(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
    ... 60 common frames omitted*
4

2 回答 2

3

我通过将此依赖项的范围设置为 test 来解决问题,因为我仅将它用于此目的:

 <dependency>
        <groupId>com.sap.cloud</groupId>
        <artifactId>neo-java-web-api</artifactId>
        <version>3.9.9</version>
        <scope>test</scope>
 </dependency>
于 2018-03-02T13:39:30.387 回答
0

这看起来像是一个类加载器问题,因为CloudConnectivityConfiguration肯定是在实现ConnectivityConfiguration,请参见下面的类图。很可能类和接口已由不同的类加载器加载。

你在使用 Spring 开发工具吗?这可能是此类问题的来源,请参阅参考资料以获取解释和潜在修复。

在此处输入图像描述

于 2018-03-02T09:46:13.560 回答