java-如何修复在应用程序启动期间SAP Cloud SDK抛出的DestinationAccessException
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java-如何修复在应用程序启动期间SAP Cloud SDK抛出的DestinationAccessException,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3113字,纯文字阅读大概需要5分钟。
内容图文
![java-如何修复在应用程序启动期间SAP Cloud SDK抛出的DestinationAccessException](/upload/InfoBanner/zyjiaocheng/670/ded35a6868fb447598ee5d541d43ac8a.jpg)
我想用Spring应用程序扩展S / 4HANA云系统.可以构建应用程序而不会出现任何错误,也可以将其部署到SAP Cloud Platform.后端应用程序启动时,将引发错误.日志中的错误如下:
[.../WEB-INF/classes/com/sap/controllers/ExportController.class]: Unsatisfied dependency expressed through constructor parameter 0;
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'exportServiceImpl' defined in file [.../WEB-INF/classes/com/sap/services/ExportServiceImpl.class]: Unsatisfied dependency expressed through constructor parameter 0;
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'adsService' defined in class path resource [com/sap/ads/service/ServiceConfiguration.class]: Bean instantiation via factory method failed;
nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.sap.ads.service.Service]: Factory method 'service' threw exception;
nested exception is com.sap.cloud.sdk.cloudplatform.connectivity.exception.DestinationAccessException: Failed to get ConnectivityConfiguration: 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?
之后,似乎该错误发生在带有DestinationAccessException的ServiceConfiguration.class中.
我已经检查并包含以下内容:
Creating ErpConfigContext threw exception
不幸的是,错误仍然相同.
这是受影响部分的实现:
服务类:
[...]
public interface Service {
[...]
public static final String DESTINATION_NAME = "myDestination";
@RequestLine("POST /example/path")
Response doSomething(Request myRequest);
}
ServiceConfiguration.class:
[...]
@Configuration
public class ServiceConfiguration {
@Bean
public Service service() {
return Feign.builder()
.encoder(new JacksonEncoder())
.decoder(new JacksonDecoder())
.client(DestinationHelper.getHttpClient(Service.DESTINATION_NAME))
.target(Service.class, DestinationHelper.getUrl(service.DESTINATION_NAME));
}
}
DestinationHelper.class:
[...]
public class DestinationHelper {
/**
* @return the URL of the destination with {@code destinationName}
*/
public static String getUrl(String destinationName) {
return DestinationAccessor
.getDestination(destinationName)
.getUri()
.toString();
}
/**
* @return an HTTP client preconfigured for the destination
*/
public static ApacheHttpClient getHttpClient(final String destinationName) {
return new ApacheHttpClient(HttpClientAccessor.getHttpClient(destinationName));
}
}
服务实现中是否实现了某些错误甚至缺失?在错误日志之后,该服务似乎实际上无法建立与目标的正确连接.
解决方法:
这里的问题是在应用程序启动期间,尚无RequestContext可用.
解决该问题的方法是将您的相关代码包装在RequestContextExecutor中,如下所示:
@Bean
public Service service() throws Exception {
return new RequestContextExecutor().execute(() -> {
return Feign.builder()
.encoder(new JacksonEncoder())
.decoder(new JacksonDecoder())
.client(DestinationHelper.getHttpClient(Service.DESTINATION_NAME))
.target(Service.class, DestinationHelper.getUrl(service.DESTINATION_NAME));
};
}
内容总结
以上是互联网集市为您收集整理的java-如何修复在应用程序启动期间SAP Cloud SDK抛出的DestinationAccessException全部内容,希望文章能够帮你解决java-如何修复在应用程序启动期间SAP Cloud SDK抛出的DestinationAccessException所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。