官方教程html
为了确保一切设置正确,本教程还包括如何构建和运行一个简单的 Hello World 应用程序。 SAP Cloud 应用程序编程模型 (CAP) 支持 Java 和 Node.js 开发。 可是对于本教程,咱们使用的是 Java。 CAP Java SDK 可以与 Spring Boot 紧密集成,Spring Boot 提供了许多开箱即用的功能。 这意味着,Spring Boot 将成为您的运行时容器。java
打开 SAP Business Technology Platform Trial 帐号,进入 Business Application Studio:spring
打开以前建立好的 dev space,若是没有,新建立一个。数据库
类型要选择成 Full Stack Cloud Application:编程
进入 space 以后,咱们在浏览器里看到了一个相似 Visual Studio Code 的在线编辑器,打开一个新的命令行窗口:浏览器
咱们当前的工做目录为:/home/user/projects:数据结构
运行以下命令行:app
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
mvn 命令执行完毕后,应该看到以下输出:编辑器
这将使用 maven archetype cds-services-archetype 初始化应用程序并建立您的项目。
该项目被命名为 products-service.
打开名为 products-service 的工做空间。
CAP 应用程序使用核心数据服务 (CDS) 来描述:
下面咱们建立一个简单的 service,其会定义属于本身的实体。
建立一个新文件:admin-service.cds
源代码以下:
service AdminService { entity Products { key ID : Integer; title : String(111); descr : String(1111); } }
命令行里执行 mvn clean install,确保看到 build success 消息:
运行此命令后,会生成一些文件并将其添加到 srv/src/main/resources/edmx 文件夹中。 这是默认路径,CAP Java 运行时在其中查找模型定义。
如您所见,该文件不包含特定于 CAP 的启动指令。 这是每一个 Spring Boot 应用程序中的典型样板代码。 CAP Java 运行时的初始化由 Spring 根据 pom.xml 中定义的依赖关系自动完成。如今能够启动这个 SpringBoot 应用了:
运行命令行:mvn clean spring-boot:run
点击 Expose and open,就能在浏览器里看到应用了:
expose port 的含义:该应用程序没有任何可从 Internet 访问的端口。 只有 SAP Business Application Studio 中的容器正在侦听某个还没有从 Internet 访问的端口。
更多Jerry的原创文章,尽在:"汪子熙":