Welcome to the bookshop-java project. It demonstrates how to build business applications using the CAP Java SDK providing a book shop web application as an example. The application in this project enables browsing books, managing books, and managing orders.

This sample application shows how to conveniently create business applications based on CDS domain models, persisting data with H2, or SAP HANA, and exposing an OData V4 frontend with an SAP Fiori frontend on top.
This sample uses Spring Boot as an application framework. Although a CAP Java application isn’t required to build on Spring Boot, it’s the first choice of framework, as it’s seamlessly integrated.
The domain models are defined using CDS entity definitions.
By default, an in-memory H2 database is used for data persistency. Once productively deployed to SAP Business Technology Platform, SAP HANA can be used.
Services are defined using CDS Service Models. The OData V4 Protocol Adapter translates the CDS service models into corresponding OData schemas and maps the incoming OData requests to the corresponding CDS services.
Although CAP provides generic event handlers to serve most CRUD requests out-of-the-box, it’s possible to add business logic through Custom Event Handlers.
A SAP Fiori UI is added using predefined SAP Fiori elements templates. SAP Fiori annotations add information to the service definitions, on how to render the data.
CAP provides built-in multitenancy support with out-of-the box tenant isolation. The sample application demonstrates usage of MTX sidecar based on streamlined MTX and can be deployed as multitenant application. The deprecated classic MTX setup is shown in the mtx-classic branch for reference.
Framework and Infrastructure related Features:
@restrict in the Admin Service)expert or premium-customer to the user.Domain Model related Features:
managed or cuid Aspect in Books@assert.formatService Model related Features:
addToOrder in the Admin Service. The Action implementation is in the Admin Service Event Handler@cds.persistence.skip in AdminServiceUser Interface related Features:
CSV filesmoveSibling in the Admin Service. This action demonstrates experimental UI feature ChangeNextSiblingAction. The Action implementation is in the Hierarchy Sibling Action HandlerCDS Maven Plugin Features:
The following sections describe how to set up, build, and run the project.
Make sure you have set up a development environment (that means, you’ve installed the CDS Compiler, Java 21, and Apache Maven) as described here. This sample application requires a Java 21 compatible JDK. We recommend using SapMachine 21.
bash
git clone https://github.com/SAP-samples/cloud-cap-samples-java.git
mvn spring-boot:run
[!NOTE] Please note that some IDEs may interfere with their autobuild when launching the application from the CLI using Maven. Therefore, please ensure that no IDEs are running in parallel or launch the application natively from your preferred IDE as described below.
Use the following links in the browser to check if everything works fine:
http://localhost:8080: This should show the automatically generated index page of served paths.
You'll start with a predefined stock of books as this procedure starts the bookshop application with a CSV-initialized in-memory H2 database.
Two mock users in addition to the default mock users
are defined for local development:
- User: user, password: user to browse books
- User: admin, password: admin to manage books and orders
You can test the GenreHierarchyTest on H2 using the profile default as well as on HANA using the profile cloud
cds bind --exec -- mvn clean install -Dspring.profiles.active=cloud
VS Code supports the project out-of-the-box, when using the Extension Pack for Java.
To launch the application in VS Code navigate to the Application class and click on Run or Debug.
Use the following steps to import the project to Eclipse:
Import the project using File > Import > Existing Maven Projects.
Now, you should see the projects bookshop and bookshop-parent in the project/package explorer view.
In Project Explorer, change the property "Package Presentation" from "Flat" to "Hierarchical" for better understanding.
To compile the project, right-click the file pom.xml in the bookshop-parent project root folder and select
Run as > Maven build.
In the following dialog, enter the string clean install into the field labeled with "Goals" and click "Run".
Note: This step also compiles the CDS artifacts, thus repeat this once you made changes to the CDS model. This step also generates source files, therefore refresh the "bookshop" project in your IDE.
To run the application, right-click the bookshop project root in the Package Explorer and select Run as > Spring Boot App (make sure you have Spring Tools 4 installed).
This step creates a default Run Configuration named Bookshop - Application and starts the application afterwards. To go on with the next step, stop the application again.
Then, set the default working directory by editing your Run Configuration via Run > Run Configurations > Bookshop - Application. On the tab Arguments change the default Working Directory to:
${workspace_loc:bookshop-parent}
Afterward, click Run. This step starts the applications main method located in src/main/java/my/bookshop/Application.java.
IntelliJ can handle the project more or less out-of-the-box. Since some of the event handlers in the project rely on the code generated from the CDS model the build path of
$ claude mcp add cloud-cap-samples-java \
-- python -m otcore.mcp_server <graph>