Как исправить исключение DestinationAccessException, которое выдает SAP Cloud SDK во время запуска приложения

Я хочу расширить облачную систему S/4HANA приложением Spring. Можно создать приложение без каких-либо ошибок, а также развернуть его в облачной платформе SAP. Когда приложение Backend запускается, оно выдает ошибку. Ошибка из журналов выглядит следующим образом:

[.../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?

После этого кажется, что ошибка происходит в ServiceConfiguration.class с DestinationAccessException.

Я уже проверил и включил это: Создание ErpConfigContext бросил исключение

К сожалению ошибка все та же.

Вот реализация затронутых частей:

Service.class:

[...]
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));
    }

}

Что-то неправильно реализовано или вообще отсутствует в реализации Сервиса? Судя по журналу ошибок, кажется, что служба не может правильно установить соединение с пунктом назначения.

1 ответ

Решение

Проблема заключается в том, что во время запуска приложения нет 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));
    };
}
Другие вопросы по тегам