快速入门
快速实现一个自定义集成的后端部分,代码示例
前置条件
在开发集成的后端部 分之前,您可能需要知道:
- Beaver IoT 的基本概念以及术语
- Java 的基本语法
- SpringFramework 的基础知识
如果您对以上的知识有一定的了解,那么请继续往下阅读,一步一步完成一个最简单的 Demo。
环境准备
在进行开发前,需要准备以下环境:
- Java IDE (推荐IntelliJ IDEA)
- Java Version 17 SDK
- Maven
- Git CLI
在准备这些完成后,运行以下git命令,获取集成开发的项目源码 beaver-iot-integrations
- SSH
- Https
git clone git@github.com:Milesight-IoT/beaver-iot-integrations.git
git clone https://github.com/Milesight-IoT/beaver-iot-integrations.git
beaver-iot-integrations/
├── integrations/ # 集成目录
│ ├── sample-integrations/ # 示例集成目录
│ │ └── ... # 示例集成
│ ├── msc-integration
│ └── ... # 所有其它集成
(可选) 接下来,获取 Beaver IoT 后端项目源码 beaver-iot ,用于集成开发完成后的测试
- SSH
- Https
git clone git@github.com:Milesight-IoT/beaver-iot.git
git clone https://github.com/Milesight-IoT/beaver-iot.git
使用Java IDE打开这两个项目后就可以开始尝试开发一个集成了。
写一个Hello world
首先,进入beaver-iot-integrations项目
创建集成元数据
在项目的integrations模块下新建一个作为这个集成的模块,并为这个模块起一个名字,作为集成的id
[integration-id]
提示
请用你刚刚生成的id替换以下所有示例代码中的[integration-id]
在模块的pom文件如下
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.milesight.beaveriot.integrations</groupId>
<artifactId>integrations</artifactId>
<version>${revision}</version>
</parent>
<artifactId>[integration-id]</artifactId>
<name>[integration-name]</name>
<description>[integration-description]</description>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>com.milesight.beaveriot</groupId>
<artifactId>context</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- in case you have your own dependencies to be packaged -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
注意
scope为provided的依赖不会被打包到集成中,而是由Beaver IoT提供,通过maven-shade-plugin插件将依赖包打包至一个jar包中。
context