官方教程
为了确保一切设置正确,本教程还包括如何构建和运行一个简单的 Hello World 应用程序。 SAP Cloud 应用程序编程模型 (CAP) 支持 Java 和 Node.js 开发。 但是对于本教程,我们使用的是 Java。 CAP Java SDK 能够与 Spring Boot 紧密集成,Spring Boot 提供了许多开箱即用的功能。 这意味着,Spring Boot 将成为您的运行时容器。
打开 SAP Business Technology Platform Trial 账号,进入 Business Application Studio:运行如下命令行:
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
如果遇到这个错误:mvn: command not found,说明之前创建的 space 类型不正确,应该选择 fullstack Cloud Application:
这将使用 maven archetype cds-services-archetype 初始化应用程序并创建您的项目。
该项目被命名为 products-service.
db 文件夹存储与数据库相关的工件。
srv 文件夹存储您的 Java 应用程序。
打开名为 products-service 的工作空间。
CAP 应用程序使用核心数据服务 (CDS) 来描述:
- 使用实体定义来描述数据结构
- 使用服务定义来描述如何消费数据结构
下面我们创建一个简单的 service,其会定义属于自己的实体。
创建一个新文件:admin-service.cdsexpose port 的含义:该应用程序没有任何可从 Internet 访问的端口。 只有 SAP Business Application Studio 中的容器正在侦听某个尚未从 Internet 访问的端口