创建ErpConfigContext时出现异常

时间:2018-03-02 06:46:21

标签: s4sdk

我在尝试创建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*

2 个答案:

答案 0 :(得分:4)

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

您使用的是Spring devtools吗?这可能是此类问题的来源,请参阅the reference以获取解释和可能的解决方法。

enter image description here

答案 1 :(得分:3)

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

 <dependency>
        <groupId>com.sap.cloud</groupId>
        <artifactId>neo-java-web-api</artifactId>
        <version>3.9.9</version>
        <scope>test</scope>
 </dependency>