Configuring Applications
Profiles and Properties
This section describes how to configure applications. CAP Java applications can fully leverage Spring Boot's capabilities for Externalized Configuration. This enables you to define multiple configuration profiles for different scenarios, like local development and cloud deployment.
For a first introduction, have a look at our sample application and the configuration profiles we added there.
Now, that you're familiar with how to configure your application, start to create your own application configuration. See the full list of CDS properties as a reference.
Production Profile
When running your application in production, it makes sense to strictly disable some development-oriented features. The production profile configures a set of selected property defaults, recommended for production deployments, at once. To specify the production profile, set cds.environment.production.profile
to a Spring profile used in production deployments.
Production profile = cloud
It is recommended to set cds.environment.production.profile
to cloud
. The Java Buildpacks set the cloud
profile for applications by default. Other active profiles for production deployments are typically set using the environment variable SPRING_PROFILES_ACTIVE
on your application in your deployment descriptors (mta.yaml
, Helm charts, etc.).
Property defaults adjusted with the production profile are the following:
- Index Page is disabled:
cds.index-page.enabled
is set tofalse
- Mock Users are strictly disabled:
cds.security.mock.enabled
is set tofalse
Note, that explicit configuration in the application takes precedence over property defaults from the production profile.
Using SAP Java Buildpack
In SAP BTP Cloud Foundry environment, the Java runtime that is used to run your application is defined by the so-called buildpack. For CAP applications, we advise you to use the SAP Java Buildpack 2. CAP applications built with Spring Boot don't require any specific configuration for the buildpack and run using Java Main runtime by default.
To configure the buildpack for Java 21 with SapMachine JRE, add the following lines to your mta.yaml
right under your Java service definition:
parameters:
buildpack: sap_java_buildpack_jakarta
properties:
JBP_CONFIG_COMPONENTS: "jres: ['com.sap.xs.java.buildpack.jre.SAPMachineJRE']"
JBP_CONFIG_SAP_MACHINE_JRE: '{ version: 21.+ }'
SAP Business Application Studio
If you develop your application in SAP Business Application Studio and Java 21 is not available there, use the Java 17, instead.
Service Bindings
In the SAP BTP, Kyma Runtime, credentials of service bindings are stored in Kubernetes secrets. Using volumes, you can mount secrets into your application's container. These volumes contain a file for each of the secrets properties.
Get the Secret into Your Container
To use a Kubernetes secret with your CAP service, you create a volume from it and mount it to the service's container.
For example:
spec:
volumes:
- name: bookshop-db-secret-vol
secret:
secretName: bookshop-db-secret
containers:
- name: app-srv
...
volumeMounts:
- name: bookshop-db-secret-vol
mountPath: /etc/secrets/sapcp/hana/bookshop-db
readOnly: true
Prepare Your CAP Application
Add the cds-feature-k8s
feature in the pom.xml file of your CAP application to consume service credentials:
<dependencies>
<!-- Features -->
<dependency>
<groupId>com.sap.cds</groupId>
<artifactId>cds-feature-k8s</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
The feature supports reading multiple credentials from a common base directory and to read credentials from arbitrary directories.
Read Credentials from a Base Directory
The base directory for service credentials is the /etc/secrets/sapcp directory. You can overwrite the default base directory with the cds.environment.k8s.secretsPath
property.
Within this base directory, the directory structure for the service credentials is <service-name>/<instance-name>.
Read Credentials from Arbitrary Directories
You can also configure service bindings using the cds.environment.k8s.serviceBindings
configuration property.
For example:
cds:
environment:
k8s:
serviceBindings:
bookshop-db:
secretsPath: /etc/secrets/hana
service: hana
plan: hdi-shared
tags:
- hana
- db
bookshop-uaa:
secretsPath: /etc/somewhere/else/xsuaa
...
The parameters plan
and tags
are optional.