1. 基础类
要加载的数组的基础类
@Data
public class Device {
/**
* 摄像机登录账户.
*/
private String account;
/**
* 摄像机登录密码.
*/
private String password;
/**
* 摄像机ip.
*/
private String deviceIp;
/**
* 摄像机端口.
*/
private short devicePort;
/**
* 用户句柄.
*/
private int lUserID;
/**
* 监听ip.
*/
private String listenIp;
/**
* 监听端口.
*/
private short listenPort;
}
2. 数组配置
@Component
@ConfigurationProperties(prefix = "device")
@Data
public class DeviceInfos {
private List<Device> deviceList;
}
3. 配置文件application.yml
application.yml 中的字段必须和device实体类中的字段一致。
device:
deviceList:
- account: admin
password: xxxxx
deviceIp: 192.168.100.xxx
devicePort: 8000
listenIp: 192.168.100.204
listenPort: 8080
4. 使用
通过@Autowired 使用DeviceInfos
@Log
@Component
public class StartListener implements ApplicationListener<ApplicationReadyEvent> {
@Autowired
private DeviceInfos deviceInfos;
@Autowired
private HCNetSDKUtils hcNetSDKUtils;
@Override
public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
log.info("SpringBoot start!");
// 打印SDK日志
HCNetSDKUtils.hCNetSDK.NET_DVR_SetLogToFile(3, ".\\SDKLog\\", false);
deviceInfos.getDeviceList().stream().forEach(device -> {
// 登录
hcNetSDKUtils.Login_V40(device);
// 开启监听
hcNetSDKUtils.StartAlarmListen(device);
});
}
}
网友评论