Integration With Cloud Application Programming Model
This document outlines how you integrate the SAP Cloud SDK into an application based on the SAP Cloud Application Programming Model (referred to as CAP in the remainder).
While this document provides a general overview of this topic, we have published a practical tutorial on SAP Developers which illustrates all steps on a comprehensive example.
We provide a guide on how to leverage the traditional Spring deployment in conjunction with CAP. That guide is applicable for your project if you need to invoke BAPIs via the SAP Java Connector library.
For all features of the SAP Cloud SDK to work seamlessly with CAP, please maintain a CAP/CDS version of at least 2.4.0
.
If for some reason you are using a version earlier than 2.4.0
and using SAP Cloud SDK's resilience features, this additional step is required:
Resolve multiple implementations of ResilienceDecorationStrategy
If you see an ObjectLookupFailedException
in your stack trace with an underlying message Found multiple implementations of ResilienceDecorationStrategy
, please add the following code to any class that gets executed on application startup:
ResilienceDecorator.setDecorationStrategy(new Resilience4jDecorationStrategy());
Please ensure that the import for the class is com.sap.cloud.sdk.cloudplatform.resilience4j.Resilience4jDecorationStrategy
and not com.sap.cloud.sdk.frameworks.resilience4j.Resilience4jDecorationStrategy
.
Integration Steps
The following instructions assume that you have an existing CAP project that can be built successfully. Furthermore, we assume that you deploy your app to the SAP BTP, Cloud Foundry environment.
Add the SAP Cloud SDK Bill-of-Material
Add the SAP Cloud SDK Bill-of-Material (BOM) into the dependencyManagement
section of the root POM.
Here is the XML snippet:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.sap.cloud.sdk</groupId>
<artifactId>sdk-bom</artifactId>
<version>use-latest-version-here</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
We recommend using the latest SAP Cloud SDK version always. Check out the release notes to see the release history.
By default, the SAP Cloud SDK archetypes reference the SAP Cloud SDK Bill-of-Material sdk-bom
, which manages dependency versions for all SAP Cloud SDK modules and transitive dependencies.
If you face dependency conflicts, you can instead try using the SAP Cloud SDK Modules Bill-of-Material sdk-modules-bom
in the dependencyManagement
section of your Maven POM file.
Add the SAP Cloud SDK Dependencies
Add the respective SAP Cloud SDK dependencies to the POM file under the srv
directory.
<dependency>
<groupId>com.sap.cloud.sdk</groupId>
<artifactId>sdk-core</artifactId>
</dependency>
Note that the version
tags can be omitted, because the SAP Cloud SDK BOM controls the version of all the SAP Cloud SDK modules.
That is, you only need to increase the version of the BOM and all modules get updated automatically.
Add the Integration Dependency
If your app uses multitenancy features and/or a protected backend, we have to integrate the tenant and user concepts of CAP and the SAP Cloud SDK.
We'll add a respective integration dependency to the POM file under the srv
directory (same place as the previous step).
<dependency>
<groupId>com.sap.cds</groupId>
<artifactId>cds-integration-cloud-sdk</artifactId>
</dependency>
The executeWith...()
methods offered by the Accessor classes (e.g. TenantAccessor
) are currently not supported when using the CAP integration.
To still manipulate the request context, please refer to the CAP documentation.
You can learn more about how the multitenancy of the SAP Cloud SDK integrates with CAP in this article.
Now the SAP Cloud SDK is integrated with the CAP application. You can go ahead using the SAP Cloud SDK features, such as querying OData services.