Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bookstore
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
郭智朋
bookstore
Commits
b29b6d81
Commit
b29b6d81
authored
Jan 14, 2025
by
guozhipeng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加数据库
parent
ce882fc9
Show whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
160 additions
and
26 deletions
+160
-26
.cdsrc.json
.cdsrc.json
+6
-0
.gitignore
.gitignore
+3
-0
README.md
README.md
+143
-22
books.zip
app/books/dist/books.zip
+0
-0
orders.zip
app/orders/dist/orders.zip
+0
-0
books.zip
app/router/books/dist/books.zip
+0
-0
orders.zip
app/router/orders/dist/orders.zip
+0
-0
package-lock.json
db/package-lock.json
+1
-1
1736838508348.png
image/README/1736838508348.png
+0
-0
1736841368712.png
image/README/1736841368712.png
+0
-0
1736841886245.png
image/README/1736841886245.png
+0
-0
1736841944317.png
image/README/1736841944317.png
+0
-0
1736842165790.png
image/README/1736842165790.png
+0
-0
pom.xml
srv/pom.xml
+5
-1
application.yaml
srv/src/main/resources/application.yaml
+2
-2
No files found.
.cdsrc.json
View file @
b29b6d81
...
...
@@ -2,6 +2,12 @@
"sql"
:
{
"native_hana_associations"
:
false
},
"build"
:
{
"target"
:
"."
},
"hana"
:
{
"deploy-format"
:
"hdbtable"
},
"requires"
:
{
"[production]"
:
{
"auth"
:
"xsuaa"
,
...
...
.gitignore
View file @
b29b6d81
...
...
@@ -29,3 +29,6 @@ hs_err*
.vscode
.idea
.reloadtrigger
# added by cds
.cdsrc-private.json
README.md
View file @
b29b6d81
# 使用说明
# 文档1:
使用 CAP for Java 构建业务应用程序
# 文档1:
设置SAP Business Application Studio for CAP Java
https://developers.sap.com/mission.cap-java-app.html
# 设置SAP Business Application Studio for CAP Java
[
https://developers.sap.com/mission.cap-java-app.html
](
)
## 本地开发环境先决条件
...
...
@@ -54,6 +52,22 @@ mvn clean spring-boot:run
浏览器访问地址:http://localhost:8080/
## 打包部署到联创杰子账户gzpTest
命令:
```
cf api https://api.cf.cn40.platform.sapcloud.cn
```
登录BTP命令:
```
cf login -a https://api.cf.cn40.platform.sapcloud.cn -o "Shenzhen-Lianchuangjie-Technology-Co-Ltd-test-cnrc164l" -s gzpTest -u zhipeng.guo@boscloud.cn
```
密码: Gzp@123456
## 创建应用程序bookstore
在添加书店项目之前,我们需要确保您位于项目文件夹中。这两个项目(产品服务和书店)应该放在一起。在新创建的终端中运行以下命令以返回到projects文件夹:
...
...
@@ -215,9 +229,9 @@ cf restart bookstore
搞定了!搞定了!您已经学习了如何将安全应用程序部署到SAP BTP、Cloud Foundry并分配所需的角色。
# 文档2:CAP部署到Cloud Foundry
# 文档2:
【仅供参考】
CAP部署到Cloud Foundry
https://cap.cloud.sap/docs/guides/deployment/to-cf
[
https://cap.cloud.sap/docs/guides/deployment/to-cf
](
)
## 先决条件
...
...
@@ -325,22 +339,6 @@ cds add mta
cds add approuter
```
## 打包部署到联创杰子账户gzpTest
命令:
```
cf api https://api.cf.cn40.platform.sapcloud.cn
```
登录BTP命令:
```
cf login -a https://api.cf.cn40.platform.sapcloud.cn -o "Shenzhen-Lianchuangjie-Technology-Co-Ltd-test-cnrc164l" -s gzpTest -u zhipeng.guo@boscloud.cn
```
密码: Gzp@123456
## Build & Assemble 构建和组装
### 使用cds build构建可部署文件
...
...
@@ -388,7 +386,130 @@ Application "bookshop" started and available at
我们没有为
`AdminService`
分配
*管理员*
角色。您需要创建一个角色集合,并
[
分配角色和您的用户
](
https://developers.sap.com/tutorials/btp-app-role-assignment.html
)
以获得访问权限。
# 文档3:HANA数据库
## 使用SAP HANA作为CAP Java应用程序的数据库
[
https://developers.sap.com/tutorials/cp-cap-java-hana-db.html#880cf07a-1788-4fda-b6dd-b5a6e5259625
](
)
通过本地CAP Java应用程序,在SAP Business Technology Platform中使用SAP HANA。
在上一个教程中,您已经将书店应用程序部署到SAP BTP。在本教程中,您将从本地运行的应用程序连接到SAP HANA Cloud on SAP BTP。通过这种混合设置,您可以在本地开发服务,同时连接到SAP HANA Cloud数据库,并缩短周转时间。
### 登录SAP BTP Cloud Foundry环境
在SAP Business Application Studio中,通过从主菜单中选择
**Terminal**
**→**
**New Terminal**
打开一个终端。
在终端中使用以下命令使用登录凭据进行身份验证:
```
cf login
```
如果需要再次指定
`<CF_API_ENDPOINT>`
,请使用在上一个教程中获得的实际值。
### 配置应用程序以在本地使用SAP HANA
在项目中添加额外的Maven依赖项。这种依赖性带来了读取SAP HANA服务绑定和配置SAP HANA连接的能力。
在前面的教程中,您已经在
`srv/pom.xml`
中添加了
`cds-starter-cloudfoundry`
依赖项。在这种情况下,您可以跳过以下内容并转至下一步。

通过单击相应的图标导航回文件资源管理器。
编辑
`srv`
目录中的
`pom.xml`
(而不是位于项目根文件夹中的
`pom.xml`
文件),并在
`<dependencies>`
标记下添加以下依赖项,并确保
**保存**
该文件:
<dependency>
<groupId>
com.sap.cds
</groupId>
<artifactId>
cds-feature-hana
</artifactId>
</dependency>
### 将数据库工件部署到SAP HANA
假设您不想使用在部署过程中创建的相同服务实例,那么您将在这里为混合测试周期创建一个具有相同数据的新服务实例。如果你想使用最近部署的版本,在下面使用
`bookstore-db`
而不是
`bookstore-hana`
。
返回到SAP Business Application Studio的终端,确保您位于书店项目的根目录中:
```
cd ~/projects/bookstore
```
`在bookstore`
项目根文件夹的
`.cdsrc.json文件`
中添加以下配置:
```
{
"hana" : {
"deploy-format": "hdbtable"
}
}
```

```
{
"sql": {
"native_hana_associations": false
},
"build": {
"target": "."
},
"hana" : {
"deploy-format": "hdbtable"
},
"requires": {
"[production]": {
"auth": "xsuaa",
"db": "hana"
}
}
}
```

确保您的SAP HANA Cloud实例已启动。
创建SAP HANA服务实例,并使用以下命令隐式地将所有工件推送到数据库:
```
cds deploy --to hana:bookstore-hana --store-credentials
```
作为一种效果,
`.hdbtable`
和
`.hdbview`
文件在
`(gen/)db/src/gen/`
文件夹中生成。
此外,该命令初始化SAP HANA HDI容器内的数据库模式。


### 在本地使用SAP HANA运行应用程序
除了初始化SAP HANA数据库外,
`cds deploy`
命令还在 bookstore 根文件夹中创建了一个名
`为default-env.json的`
文件。此文件包含一组凭据,用于连接到由命令创建的SAP HANA HDI容器。CAP Java能够自动从该文件中获取SAP HANA凭据,并将本地运行的应用程序配置为使用SAP HANA HDI容器作为数据库。
将应用程序部署到云时,Cloud Foundry将通过Open Service Broker API将凭据作为服务绑定提供给应用程序。同样在这种情况下,CAP Java将自动获取SAP HANA凭据并为您配置应用程序,您将在下一个教程中看到。
在启动应用程序之前,请确保在终端或调试侧面板中停止所有正在运行的实例。
让我们来测试SAP HANA连接。通过运行以下命令启动应用程序:
```
mvn spring-boot:run -Dspring-boot.run.profiles=cloud
```
Java系统属性
`-Dspring-boot.run.profiles=cloud`
确保使用H2作为数据库的默认配置不会被激活,该默认配置仍然在
`application.yaml`
中定义。
您可以观察到日志行
`Registered DataSource 'ds-bookstore-hana'`
,这表明SAP HANA配置已拾取。
打开文件
`requests.http`
并执行创建订单的其中一个请求,方法是选择其上方
**的SendRequest**
。
使用相同的命令重新启动应用程序,并浏览到WelcomePage上的
`Orders`
实体。您可以看到这些条目是持久化的。
恭喜你,恭喜你
您已经成功地将数据库模式部署到SAP HANA并连接了本地运行的应用程序。在下面的教程中,您将使用本教程中创建的SAP HANA服务实例在SAP BTP,Cloud Foundry环境中运行应用程序。
# 结束 2025-01-14
app/books/dist/books.zip
View file @
b29b6d81
No preview for this file type
app/orders/dist/orders.zip
View file @
b29b6d81
No preview for this file type
app/router/books/dist/books.zip
View file @
b29b6d81
No preview for this file type
app/router/orders/dist/orders.zip
View file @
b29b6d81
No preview for this file type
db/package-lock.json
View file @
b29b6d81
...
...
@@ -10,7 +10,7 @@
"hdb"
:
"^0"
},
"engines"
:
{
"node"
:
"^2
2
.0.0"
"node"
:
"^2
0
.0.0"
}
},
"node_modules/@sap/hdi"
:
{
...
...
image/README/1736838508348.png
0 → 100644
View file @
b29b6d81
6.7 KB
image/README/1736841368712.png
0 → 100644
View file @
b29b6d81
12.6 KB
image/README/1736841886245.png
0 → 100644
View file @
b29b6d81
32.6 KB
image/README/1736841944317.png
0 → 100644
View file @
b29b6d81
53 KB
image/README/1736842165790.png
0 → 100644
View file @
b29b6d81
61 KB
srv/pom.xml
View file @
b29b6d81
...
...
@@ -54,6 +54,10 @@
<artifactId>
spring-boot-starter-actuator
</artifactId>
</dependency>
<dependency>
<groupId>
com.sap.cds
</groupId>
<artifactId>
cds-feature-hana
</artifactId>
</dependency>
</dependencies>
<build>
...
...
@@ -122,7 +126,7 @@
<configuration>
<commands>
<command>
build --for java
</command>
<
command>
deploy --to h2 --dry --out "${project.basedir}/src/main/resources/schema-h2.sql"
</command
>
<
!--<command>deploy --to h2 --dry --out "${project.basedir}/src/main/resources/schema-h2.sql"</command>--
>
</commands>
</configuration>
</execution>
...
...
srv/src/main/resources/application.yaml
View file @
b29b6d81
---
spring
:
config.activate.on-profile
:
default
sql.init.schema-locations
:
classpath:schema-h2.sql
#
sql.init.schema-locations: classpath:schema-h2.sql
cds
:
data-source.auto-config.enabled
:
fals
e
data-source.auto-config.enabled
:
tru
e
security
:
mock
:
users
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment