头图

official tutorial

To make sure everything is set up correctly, this tutorial also includes how to build and run a simple Hello World application. The SAP Cloud Application Programming Model (CAP) supports Java and Node.js development. But for this tutorial, we are using Java. CAP Java SDK can be tightly integrated with Spring Boot, and Spring Boot provides many out-of-the-box features. This means that Spring Boot will become your runtime container.

Open the SAP Business Technology Platform Trial account and enter the Business Application Studio:

Open the previously created dev space, if not, create a new one.

The type should be selected as Full Stack Cloud Application:

After entering the space, we saw an online editor similar to Visual Studio Code in the browser, and opened a new command line window:

Our current working directory is: /home/user/projects:

Run the following command line:

mvn -B archetype:generate -DarchetypeArtifactId=cds-services-archetype -DarchetypeGroupId=com.sap.cds \
-DarchetypeVersion=RELEASE \
-DgroupId=com.sap.cap -DartifactId=products-service -Dpackage=com.sap.cap.productsservice

If you encounter this error: mvn: command not found, it means that the previously created space type is incorrect, you should choose fullstack Cloud Application:

After the mvn command is executed, you should see the following output:

This will use maven archetype cds-services-archetype to initialize the application and create your project.

The project is named products-service.

  • The db folder stores artifacts related to the database.
  • The srv folder stores your Java applications.

Open the workspace named products-service.

The CAP application uses Core Data Services (CDS) to describe:

  • Use entity definitions to describe data structures
  • Use service definitions to describe how to consume data structures

Below we create a simple service, which will define its own entities.

Create a new file: admin-service.cds

The source code is as follows:

service AdminService {
    entity Products {
        key ID : Integer;
        title  : String(111);
        descr  : String(1111);
    }
}

Execute mvn clean install in the command line and make sure to see the build success message:

After running this command, some files will be generated and added to the srv/src/main/resources/edmx folder. This is the default path where the CAP Java runtime looks for model definitions.

As you can see, this file does not contain CAP-specific startup instructions. This is the typical boilerplate code in every Spring Boot application. The initialization of the CAP Java runtime is automatically completed by Spring according to the dependencies defined in pom.xml. Now you can start the SpringBoot application:

Run the command line: mvn clean spring-boot:run

Click Expose and open, you can see the application in the browser:

The meaning of expose port: The application does not have any port accessible from the Internet. Only the container in SAP Business Application Studio is listening on a port that is not yet accessible from the Internet.

More original articles by Jerry, all in: "Wang Zixi":


注销
1k 声望1.6k 粉丝

invalid