First, create a new file in the project root directory manifest.yml
with the following content:
---
applications:
- name: bookstore
path: srv/target/bookstore-exec.jar
random-route: true
services:
- bookstore-hana
The file describes the name of the application and the path where the application archive can be found. Spring Boot applications can be deployed from a single JAR archive, as indicated by the path field value above: srv/target/bookstore-exec.jar
.
The application's routes (ie, available HTTP endpoints) are randomly generated ( random-route: true
) to prevent conflicts with other application routes.
The name of the previous SAP HANA service instance is bookstore-hana
used here under the Services section (bookstore-hana).
Cloud Foundry uses Open Service Broker API
to serve applications. When running an application on Cloud Foundry, the environment variable VCAP_SERVICES (similar to the content of default-env.json) can be used, which contains all required service credentials. CAP Java can automatically read this environment variable and configure your application to use the SAP HANA database.
The described functionality is again available as another plugin in CAP Java. Therefore, you need to add additional Maven dependencies to the project. This dependency will bring the ability to read service bindings from Cloud Foundry's VCAP_SERVICES environment variable.
In order to use CloudFoundry Open Service Broker API
, you need pom.xml
to add the following dependencies in:
<dependency>
<groupId>com.sap.cds</groupId>
<artifactId>cds-feature-cloudfoundry</artifactId>
</dependency>
Even with the Cloud Foundry feature enabled, CAP Java ensures that the application can still run locally, using SQLite or SAP HANA automatically configured based on default-env.json. It provides a seamless developer experience in all environments.
If we add an extra Java system property -Dspring-boot.run.profiles=cloud to the application to ensure that the default SQLite configuration in application.yaml does not take effect. The Cloud Foundry Java Buildpack is done automatically when you deploy your application to Cloud Foundry.
mvn clean install
Build using the command line :
Deploy with cf push:
The final generated application url:
https://bookstore-cheerful-baboon-hl.cfapps.us10.hana.ondemand.com/