springboot 实现mqtt物联网的示例代码

2025-05-29 0 22

Springboot整合mybatisPlus+mysql+druid+swaggerUI+ mqtt 整合mqtt整合druid整合mybatis-plus完整pom完整yml整合swaggerUi整合log4j MQTT 物联网系统基本架构本物联网系列
mqtt)

整合mqtt

  1. <!–mqtt依赖–>
  2. <dependency>
  3. <groupId>org.springframework.boot</groupId>
  4. <artifactId>spring-boot-starter-integration</artifactId>
  5. </dependency>
  6. <dependency>
  7. <groupId>org.springframework.integration</groupId>
  8. <artifactId>spring-integration-stream</artifactId>
  9. </dependency>
  10. <dependency>
  11. <groupId>org.springframework.integration</groupId>
  12. <artifactId>spring-integration-mqtt</artifactId>
  13. </dependency>

yml

  1. iot:
  2. mqtt:
  3. clientId: ${random.value}
  4. defaultTopic: topic
  5. shbykjTopic: shbykj_topic
  6. url: tcp://127.0.0.1:1883
  7. username: admin
  8. password: admin
  9. completionTimeout: 3000
  1. package com.shbykj.handle.mqtt;
  2. import lombok.Getter;
  3. import lombok.Setter;
  4. import org.springframework.boot.context.properties.ConfigurationProperties;
  5. import org.springframework.integration.annotation.IntegrationComponentScan;
  6. import org.springframework.stereotype.Component;
  7. /**
  8. * @Author: wxm
  9. * @Description: mqtt基础配置类
  10. */
  11. @Getter
  12. @Setter
  13. @Component
  14. @IntegrationComponentScan
  15. @ConfigurationProperties(prefix = "iot.mqtt")
  16. public class BykjMqttConfig {
  17. /*
  18. *
  19. * 服务地址
  20. */
  21. private String url;
  22. /**
  23. * 客户端id
  24. */
  25. private String clientId;
  26. /*
  27. *
  28. * 默认主题
  29. */
  30. private String defaultTopic;
  31. /*
  32. *
  33. * 用户名和密码*/
  34. private String username;
  35. private String password;
  36. /**
  37. * 超时时间
  38. */
  39. private int completionTimeout;
  40. /**
  41. * shbykj自定义主题
  42. */
  43. private String shbykjTopic;
  44. }
  1. package com.shbykj.handle.mqtt.producer;
  2. import org.springframework.integration.annotation.MessagingGateway;
  3. import org.springframework.integration.mqtt.support.MqttHeaders;
  4. import org.springframework.messaging.handler.annotation.Header;
  5. /**
  6. * @description rabbitmq mqtt协议网关接口
  7. * @date 2020/6/8 18:26
  8. */
  9. @MessagingGateway(defaultRequestChannel = "iotMqttInputChannel")
  10. public interface IotMqttGateway {
  11. void sendMessage2Mqtt(String data);
  12. void sendMessage2Mqtt(String data, @Header(MqttHeaders.TOPIC) String topic);
  13. void sendMessage2Mqtt(@Header(MqttHeaders.TOPIC) String topic, @Header(MqttHeaders.QOS) int qos, String payload);
  14. }
  1. package com.shbykj.handle.mqtt;
  2. import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
  3. import org.slf4j.Logger;
  4. import org.slf4j.LoggerFactory;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.context.annotation.Bean;
  7. import org.springframework.context.annotation.Configuration;
  8. import org.springframework.integration.annotation.ServiceActivator;
  9. import org.springframework.integration.channel.DirectChannel;
  10. import org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory;
  11. import org.springframework.integration.mqtt.core.MqttPahoClientFactory;
  12. import org.springframework.messaging.MessageChannel;
  13. import org.springframework.messaging.MessageHandler;
  14. import org.springframework.messaging.MessagingException;
  15. @Configuration
  16. public class IotMqttProducerConfig {
  17. public final Logger logger = LoggerFactory.getLogger(this.getClass());
  18. @Autowired
  19. private BykjMqttConfig mqttConfig;
  20. /*
  21. *
  22. * MQTT连接器选项
  23. * *
  24. */
  25. @Bean(value = "getMqttConnectOptions")
  26. public MqttConnectOptions getMqttConnectOptions1() {
  27. MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
  28. // 设置是否清空session,这里如果设置为false表示服务器会保留客户端的连接记录,这里设置为true表示每次连接到服务器都以新的身份连接
  29. mqttConnectOptions.setCleanSession(true);
  30. // 设置超时时间 单位为秒
  31. mqttConnectOptions.setConnectionTimeout(mqttConfig.getCompletionTimeout());
  32. mqttConnectOptions.setAutomaticReconnect(true);
  33. mqttConnectOptions.setUserName(mqttConfig.getUsername());
  34. mqttConnectOptions.setPassword(mqttConfig.getPassword().toCharArray());
  35. mqttConnectOptions.setServerURIs(new String[]{mqttConfig.getUrl()});
  36. // 设置会话心跳时间 单位为秒 服务器会每隔1.5*20秒的时间向客户端发送心跳判断客户端是否在线,但这个方法并没有重连的机制
  37. mqttConnectOptions.setKeepAliveInterval(10);
  38. // 设置“遗嘱”消息的话题,若客户端与服务器之间的连接意外中断,服务器将发布客户端的“遗嘱”消息。
  39. //mqttConnectOptions.setWill("willTopic", WILL_DATA, 2, false);
  40. return mqttConnectOptions;
  41. }
  42. /**
  43. * mqtt工厂
  44. *
  45. * @return
  46. */
  47. @Bean
  48. public MqttPahoClientFactory mqttClientFactory() {
  49. DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
  50. // factory.setServerURIs(mqttConfig.getServers());
  51. factory.setConnectionOptions(getMqttConnectOptions1());
  52. return factory;
  53. }
  54. @Bean
  55. public MessageChannel iotMqttInputChannel() {
  56. return new DirectChannel();
  57. }
  58. // @Bean
  59. // @ServiceActivator(inputChannel = "iotMqttInputChannel")
  60. // public MessageHandler mqttOutbound() {
  61. // MqttPahoMessageHandler messageHandler = new MqttPahoMessageHandler(mqttConfig.getClientId(), mqttClientFactory());
  62. // messageHandler.setAsync(false);
  63. // messageHandler.setDefaultQos(2);
  64. // messageHandler.setDefaultTopic(mqttConfig.getDefaultTopic());
  65. // return messageHandler;
  66. // }
  67. @Bean
  68. @ServiceActivator(inputChannel = "iotMqttInputChannel")
  69. public MessageHandler handlerTest() {
  70. return message -> {
  71. try {
  72. String string = message.getPayload().toString();
  73. System.out.println(string);
  74. } catch (MessagingException ex) {
  75. ex.printStackTrace();
  76. logger.info(ex.getMessage());
  77. }
  78. };
  79. }
  80. }
  1. package com.shbykj.handle.mqtt;
  2. import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
  3. import org.slf4j.Logger;
  4. import org.slf4j.LoggerFactory;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.context.annotation.Bean;
  7. import org.springframework.context.annotation.Configuration;
  8. import org.springframework.integration.annotation.ServiceActivator;
  9. import org.springframework.integration.channel.DirectChannel;
  10. import org.springframework.integration.core.MessageProducer;
  11. import org.springframework.integration.mqtt.core.DefaultMqttPahoClientFactory;
  12. import org.springframework.integration.mqtt.core.MqttPahoClientFactory;
  13. import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter;
  14. import org.springframework.integration.mqtt.outbound.MqttPahoMessageHandler;
  15. import org.springframework.integration.mqtt.support.DefaultPahoMessageConverter;
  16. import org.springframework.messaging.Message;
  17. import org.springframework.messaging.MessageChannel;
  18. import org.springframework.messaging.MessageHandler;
  19. import org.springframework.messaging.MessagingException;
  20. /**
  21. * @Author: xiaofu
  22. * @Description: 消息订阅配置
  23. * @date 2020/6/8 18:24
  24. */
  25. @Configuration
  26. public class IotMqttSubscriberConfig {
  27. public final Logger logger = LoggerFactory.getLogger(this.getClass());
  28. @Autowired
  29. private MqttReceiveHandle mqttReceiveHandle;
  30. @Autowired
  31. private BykjMqttConfig mqttConfig;
  32. /*
  33. *
  34. * MQTT连接器选项
  35. * *
  36. */
  37. @Bean(value = "getMqttConnectOptions")
  38. public MqttConnectOptions getMqttConnectOptions1() {
  39. MqttConnectOptions mqttConnectOptions = new MqttConnectOptions();
  40. // 设置是否清空session,这里如果设置为false表示服务器会保留客户端的连接记录,这里设置为true表示每次连接到服务器都以新的身份连接
  41. mqttConnectOptions.setCleanSession(true);
  42. // 设置超时时间 单位为秒
  43. mqttConnectOptions.setConnectionTimeout(10);
  44. mqttConnectOptions.setAutomaticReconnect(true);
  45. // mqttConnectOptions.setUserName(mqttConfig.getUsername());
  46. // mqttConnectOptions.setPassword(mqttConfig.getPassword().toCharArray());
  47. mqttConnectOptions.setServerURIs(new String[]{mqttConfig.getUrl()});
  48. // 设置会话心跳时间 单位为秒 服务器会每隔1.5*20秒的时间向客户端发送心跳判断客户端是否在线,但这个方法并没有重连的机制
  49. mqttConnectOptions.setKeepAliveInterval(10);
  50. // 设置“遗嘱”消息的话题,若客户端与服务器之间的连接意外中断,服务器将发布客户端的“遗嘱”消息。
  51. //mqttConnectOptions.setWill("willTopic", WILL_DATA, 2, false);
  52. return mqttConnectOptions;
  53. }
  54. /*
  55. *
  56. *MQTT信息通道(生产者)
  57. **
  58. */
  59. @Bean
  60. public MessageChannel iotMqttOutboundChannel() {
  61. return new DirectChannel();
  62. }
  63. /*
  64. *
  65. *MQTT消息处理器(生产者)
  66. **
  67. */
  68. @Bean
  69. @ServiceActivator(inputChannel = "iotMqttOutboundChannel")
  70. public MessageHandler mqttOutbound() {
  71. MqttPahoMessageHandler messageHandler = new MqttPahoMessageHandler(mqttConfig.getClientId(), mqttClientFactory());
  72. messageHandler.setAsync(true);
  73. messageHandler.setDefaultTopic(mqttConfig.getDefaultTopic());
  74. return messageHandler;
  75. }
  76. /*
  77. *
  78. *MQTT工厂
  79. **
  80. */
  81. @Bean
  82. public MqttPahoClientFactory mqttClientFactory() {
  83. DefaultMqttPahoClientFactory factory = new DefaultMqttPahoClientFactory();
  84. // factory.setServerURIs(mqttConfig.getServers());
  85. factory.setConnectionOptions(getMqttConnectOptions1());
  86. return factory;
  87. }
  88. /*
  89. *
  90. *MQTT信息通道(消费者)
  91. **
  92. */
  93. @Bean
  94. public MessageChannel iotMqttInputChannel() {
  95. return new DirectChannel();
  96. }
  97. /**
  98. * 配置client,监听的topic
  99. * MQTT消息订阅绑定(消费者)
  100. ***/
  101. @Bean
  102. public MessageProducer inbound() {
  103. MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter(mqttConfig.getClientId(), mqttClientFactory(), mqttConfig.getDefaultTopic(), mqttConfig.getShbykjTopic());
  104. adapter.setCompletionTimeout(mqttConfig.getCompletionTimeout());
  105. adapter.setConverter(new DefaultPahoMessageConverter());
  106. adapter.setQos(2);
  107. adapter.setOutputChannel(iotMqttInputChannel());
  108. return adapter;
  109. }
  110. /**
  111. * @author wxm
  112. * @description 消息订阅
  113. * @date 2020/6/8 18:20
  114. */
  115. @Bean
  116. @ServiceActivator(inputChannel = "iotMqttInputChannel")
  117. public MessageHandler handler() {
  118. return new MessageHandler() {
  119. @Override
  120. public void handleMessage(Message<?> message) throws MessagingException {
  121. //处理接收消息
  122. try {
  123. mqttReceiveHandle.handle(message);
  124. } catch (Exception e) {
  125. logger.warn("消息处理异常"+e.getMessage());
  126. e.printStackTrace();
  127. }
  128. }
  129. };
  130. }
  131. }
  1. package com.shbykj.handle.mqtt;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.shbykj.handle.common.DataCheck;
  4. import com.shbykj.handle.common.RedisKey;
  5. import com.shbykj.handle.common.RedisUtils;
  6. import com.shbykj.handle.common.constants.Constants;
  7. import com.shbykj.handle.common.model.ShbyCSDeviceEntity;
  8. import com.shbykj.handle.common.model.sys.SysInstrument;
  9. import com.shbykj.handle.resolve.mapper.SysInstrumentMapper;
  10. import com.shbykj.handle.resolve.util.DateUtils;
  11. import com.shbykj.handle.resolve.util.ShbyCSDeviceUtils;
  12. import lombok.extern.slf4j.Slf4j;
  13. import org.apache.commons.collections.BidiMap;
  14. import org.apache.commons.collections.bidimap.DualHashBidiMap;
  15. import org.apache.commons.lang3.StringUtils;
  16. import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
  17. import org.eclipse.paho.client.mqttv3.MqttCallback;
  18. import org.eclipse.paho.client.mqttv3.MqttMessage;
  19. import org.slf4j.Logger;
  20. import org.slf4j.LoggerFactory;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.beans.factory.annotation.Value;
  23. import org.springframework.integration.mqtt.support.MqttHeaders;
  24. import org.springframework.messaging.Message;
  25. import org.springframework.stereotype.Component;
  26. import org.springframework.transaction.annotation.Transactional;
  27. import java.text.SimpleDateFormat;
  28. import java.util.Date;
  29. import java.util.HashMap;
  30. import java.util.Map;
  31. /*
  32. *
  33. * mqtt客户端消息处理类
  34. * **/
  35. @Component
  36. @Slf4j
  37. @Transactional
  38. public class MqttReceiveHandle implements MqttCallback {
  39. private static final Logger logger = LoggerFactory.getLogger(MqttReceiveHandle.class);
  40. @Value("${shbykj.checkCrc}")
  41. private boolean checkcrc;
  42. @Autowired
  43. private SysInstrumentMapper sysInstrumentMapper;
  44. @Autowired
  45. private RedisUtils redisUtils;
  46. public static BidiMap bidiMap = new DualHashBidiMap();
  47. //记录bykj协议内容
  48. public static Map<String, Map<String, Object>> devMap = new HashMap();
  49. //记录上限数量
  50. // public static Map<String, ChannelHandlerContext> ctxMap = new HashMap();
  51. public void handle(Message<?> message) {
  52. try {
  53. logger.info("{},客户端号:{},主题:{},QOS:{},消息接收到的数据:{}", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()), message.getHeaders().get(MqttHeaders.ID), message.getHeaders().get(MqttHeaders.RECEIVED_TOPIC), message.getHeaders().get(MqttHeaders.RECEIVED_QOS), message.getPayload());
  54. //处理mqtt数据
  55. this.handle(message.getPayload().toString());
  56. } catch (Exception e) {
  57. e.printStackTrace();
  58. log.error("处理错误" + e.getMessage());
  59. }
  60. }
  61. private void handle(String str) throws Exception {
  62. boolean flag = this.dataCheck(str);
  63. if (flag) {
  64. ShbyCSDeviceEntity shbyCSDeviceEntity = ShbyCSDeviceUtils.convertToSysInstrumentEntity(str);
  65. String deviceNumber = shbyCSDeviceEntity.getPN();
  66. String smpId = shbyCSDeviceEntity.getSMP_ID();
  67. String smpName = shbyCSDeviceEntity.getSMP_NAME();
  68. String smpWt = shbyCSDeviceEntity.getSMP_WT();
  69. if (StringUtils.isEmpty(smpId) || StringUtils.isEmpty(smpName) || StringUtils.isEmpty(smpWt)) {
  70. log.error("过滤无实际作用报文信息", str);
  71. logger.error("过滤无实际作用报文信息", str);
  72. return;
  73. }
  74. //判断设备id是否存在数据库中,存在才进行数据部分处理
  75. //不存在就提醒需要添加设备:
  76. QueryWrapper<SysInstrument> wrapper = new QueryWrapper();
  77. wrapper.eq("number", deviceNumber);
  78. wrapper.eq("is_deleted", Constants.NO);
  79. SysInstrument sysInstrument = sysInstrumentMapper.selectOne(wrapper);
  80. if (null == sysInstrument) {
  81. log.error("碳氧仪不存在或已删除,设备号:{}", deviceNumber);
  82. logger.error("碳氧仪不存在或已删除,设备号:{}", deviceNumber);
  83. return;
  84. }
  85. try {
  86. //增加实时数据
  87. String instrumentId = sysInstrument.getId().toString();
  88. String realDataKey = RedisKey.CSdevice_DATA_KEY + instrumentId;
  89. this.redisUtils.set(realDataKey, shbyCSDeviceEntity);
  90. System.out.println(shbyCSDeviceEntity);
  91. //通讯时间
  92. String onlineTime = "shbykj_mqtt:onlines:" + instrumentId;
  93. this.redisUtils.set(onlineTime, shbyCSDeviceEntity.getDataTime(), (long) Constants.RedisTimeOut.REAL_TIME_OUT);
  94. log.info("实时数据已经更新:设备主键id" + instrumentId);
  95. logger.info("{} 实时数据已经更新:设备主键id:{}",new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()),instrumentId);
  96. } catch (Exception var1) {
  97. log.error("redis处理实时报文数据逻辑异常 :" + var1.getMessage());
  98. logger.error("redis处理实时报文数据逻辑异常 :" + var1.getMessage());
  99. }
  100. }
  101. }
  102. private boolean dataCheck(String message) {
  103. boolean flag = DataCheck.receiverCheck(message);
  104. if (!flag) {
  105. return false;
  106. } else {
  107. int i = message.indexOf("QN=");
  108. if (i < 0) {
  109. log.warn("数据包中没有QN号码: " + message);
  110. logger.warn("数据包中没有QN号码: " + message);
  111. return false;
  112. } else {
  113. i = message.indexOf("PN=");
  114. if (i < 0) {
  115. log.warn("数据包中没有PN号码: " + message);
  116. logger.warn("数据包中没有PN号码: " + message);
  117. return false;
  118. } else {
  119. if (this.checkcrc) {
  120. flag = DataCheck.checkCrc(message);
  121. if (!flag) {
  122. log.warn("crc校验失败: " + message);
  123. logger.warn("数据包中没有PN号码: " + message);
  124. return false;
  125. }
  126. }
  127. return true;
  128. }
  129. }
  130. }
  131. }
  132. /**
  133. * 连接丢失
  134. *
  135. * @param throwable
  136. */
  137. @Override
  138. public void connectionLost(Throwable throwable) {
  139. logger.warn("连接丢失-客户端:{},原因:{}", throwable.getMessage());
  140. }
  141. /**
  142. * 消息已到达
  143. *
  144. * @param s
  145. * @param mqttMessage
  146. * @throws Exception
  147. */
  148. @Override
  149. public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
  150. }
  151. /**
  152. * 完成消息回调
  153. *
  154. * @param iMqttDeliveryToken
  155. */
  156. @Override
  157. public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
  158. }
  159. }

整合druid

pom

  1. <dependency>
  2. <groupId>com.alibaba</groupId>
  3. <artifactId>druid-spring-boot-starter</artifactId>
  4. <version>1.1.10</version>
  5. </dependency>

druid-bean.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:aop="http://www.springframework.org/schema/aop" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="
  5. http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans.xsd
  7. http://www.springframework.org/schema/aop
  8. http://www.springframework.org/schema/aop/spring-aop.xsd">
  9. <!– 配置_Druid和Spring关联监控配置 –>
  10. <bean id="druid-stat-interceptor"
  11. class="com.alibaba.druid.support.spring.stat.DruidStatInterceptor"></bean>
  12. <!– 方法名正则匹配拦截配置 –>
  13. <bean id="druid-stat-pointcut" class="org.springframework.aop.support.JdkRegexpMethodPointcut"
  14. scope="prototype">
  15. <property name="patterns">
  16. <list>
  17. <value>com.shbykj.*.service.*.impl.*</value>
  18. </list>
  19. </property>
  20. </bean>
  21. <aop:config proxy-target-class="true">
  22. <aop:advisor advice-ref="druid-stat-interceptor"
  23. pointcut-ref="druid-stat-pointcut" />
  24. </aop:config>
  25. </beans>

yml

  1. #spring
  2. spring:
  3. main:
  4. allowbeandefinitionoverriding: true
  5. # mysql DATABASE CONFIG
  6. datasource:
  7. druid:
  8. filters: stat,wall,log4j2
  9. continueOnError: true
  10. type: com.alibaba.druid.pool.DruidDataSource
  11. url: jdbc:mysql://localhost:3306/mqttdb?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&allowPublicKeyRetrieval=true
  12. username: root
  13. password: 123456
  14. driverclassname: com.mysql.jdbc.Driver
  15. # see https://github.com/alibaba/druid
  16. initialSize: 15
  17. minIdle: 10
  18. maxActive: 200
  19. maxWait: 60000
  20. timeBetweenEvictionRunsMillis: 60000
  21. validationQuery: SELECT 1
  22. testWhileIdle: true
  23. testOnBorrow: false
  24. testOnReturn: false
  25. poolPreparedStatements: true
  26. keepAlive: true
  27. maxPoolPreparedStatementPerConnectionSize: 50
  28. connectionProperties:
  29. druid.stat.mergeSql: true
  30. druid.stat.slowSqlMillis: 5000

启动类加上注解@ImportResource( locations = {"classpath:druid-bean.xml"} )

springboot 实现mqtt物联网的示例代码

整合mybatis-plus

pom

  1. <!–mybatis-plus–>
  2. <dependency>
  3. <groupId>com.baomidou</groupId>
  4. <artifactId>spring-wind</artifactId>
  5. <version>1.1.5</version>
  6. <exclusions>
  7. <exclusion>
  8. <groupId>com.baomidou</groupId>
  9. <artifactId>mybatis-plus</artifactId>
  10. </exclusion>
  11. </exclusions>
  12. </dependency>
  13. <dependency>
  14. <groupId>com.baomidou</groupId>
  15. <version>3.1.2</version>
  16. <artifactId>mybatis-plus-boot-starter</artifactId>
  17. </dependency>
  18. <dependency>
  19. <groupId>mysql</groupId>
  20. <artifactId>mysql-connector-java</artifactId>
  21. <version>5.1.44</version>
  22. </dependency>
  23. <!–PageHelper分页插件–>
  24. <dependency>
  25. <groupId>com.github.pagehelper</groupId>
  26. <artifactId>pagehelper-spring-boot-starter</artifactId>
  27. <version>1.2.12</version>
  28. </dependency>

yml

  1. #mybatis
  2. mybatisplus:
  3. mapperlocations: classpath:/mapper/*.xml
  4. typeAliasesPackage: org.spring.springboot.entity
  5. globalconfig:
  6. #主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
  7. idtype: 3
  8. #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
  9. fieldstrategy: 2
  10. #驼峰下划线转换
  11. dbcolumnunderline: true
  12. #刷新mapper 调试神器
  13. refreshmapper: true
  14. configuration:
  15. mapunderscoretocamelcase: true
  16. cacheenabled: false

启动类注解@MapperScan({"com.shbykj.handle.resolve.mapper"})

完整pom

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>2.4.1</version>
  9. <relativePath/> <!– lookup parent from repository –>
  10. </parent>
  11. <groupId>com.shbykj</groupId>
  12. <artifactId>handle</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <name>handle</name>
  15. <description>Demo project for Spring Boot</description>
  16. <properties>
  17. <java.version>1.8</java.version>
  18. </properties>
  19. <dependencies>
  20. <!–注意: <scope>compile</scope> 这里是正式环境,解决启动报错–>
  21. <!–idea springboot启动报SLF4J:Failed to load class “org.slf4j.impl.StaticLoggerBinder–>
  22. <!–参考:https://blog.csdn.net/u010696630/article/details/84991116–>
  23. <dependency>
  24. <groupId>org.slf4j</groupId>
  25. <artifactId>slf4j-simple</artifactId>
  26. <version>1.7.25</version>
  27. <scope>compile</scope>
  28. </dependency>
  29. <!– Log4j2 –>
  30. <dependency>
  31. <groupId>org.springframework.boot</groupId>
  32. <artifactId>spring-boot-starter-log4j2</artifactId>
  33. </dependency>
  34. <!–开启日志注解–>
  35. <dependency>
  36. <groupId>org.projectlombok</groupId>
  37. <artifactId>lombok</artifactId>
  38. </dependency>
  39. <!– 排除 Spring-boot-starter 默认的日志配置 –>
  40. <dependency>
  41. <groupId>org.springframework.boot</groupId>
  42. <artifactId>spring-boot-starter</artifactId>
  43. <exclusions>
  44. <exclusion>
  45. <groupId>org.springframework.boot</groupId>
  46. <artifactId>spring-boot-starter-logging</artifactId>
  47. </exclusion>
  48. </exclusions>
  49. </dependency>
  50. <!–swagger api接口生成–>
  51. <dependency>
  52. <groupId>io.springfox</groupId>
  53. <artifactId>springfox-swagger-ui</artifactId>
  54. <version>2.9.2</version>
  55. </dependency>
  56. <!– 代码生成器的依赖 –>
  57. <dependency>
  58. <groupId>io.springfox</groupId>
  59. <artifactId>springfox-swagger2</artifactId>
  60. <version>2.9.2</version>
  61. <exclusions>
  62. <exclusion>
  63. <groupId>com.google.guava</groupId>
  64. <artifactId>guava</artifactId>
  65. </exclusion>
  66. </exclusions>
  67. </dependency>
  68. <!–mybatis-plus–>
  69. <dependency>
  70. <groupId>com.baomidou</groupId>
  71. <artifactId>spring-wind</artifactId>
  72. <version>1.1.5</version>
  73. <exclusions>
  74. <exclusion>
  75. <groupId>com.baomidou</groupId>
  76. <artifactId>mybatis-plus</artifactId>
  77. </exclusion>
  78. </exclusions>
  79. </dependency>
  80. <dependency>
  81. <groupId>com.baomidou</groupId>
  82. <version>3.1.2</version>
  83. <artifactId>mybatis-plus-boot-starter</artifactId>
  84. </dependency>
  85. <dependency>
  86. <groupId>mysql</groupId>
  87. <artifactId>mysql-connector-java</artifactId>
  88. <version>5.1.44</version>
  89. </dependency>
  90. <dependency>
  91. <groupId>com.alibaba</groupId>
  92. <artifactId>druid-spring-boot-starter</artifactId>
  93. <version>1.1.10</version>
  94. </dependency>
  95. <!–PageHelper分页插件–>
  96. <dependency>
  97. <groupId>com.github.pagehelper</groupId>
  98. <artifactId>pagehelper-spring-boot-starter</artifactId>
  99. <version>1.2.12</version>
  100. </dependency>
  101. <!–devtools热部署–>
  102. <dependency>
  103. <groupId>org.springframework.boot</groupId>
  104. <artifactId>spring-boot-devtools</artifactId>
  105. <optional>true</optional>
  106. <scope>runtime</scope>
  107. </dependency>
  108. <!–json转换工具–>
  109. <dependency>
  110. <groupId>com.google.code.gson</groupId>
  111. <artifactId>gson</artifactId>
  112. </dependency>
  113. <!– redis –>
  114. <dependency>
  115. <groupId>org.springframework.boot</groupId>
  116. <artifactId>spring-boot-starter-data-redis</artifactId>
  117. </dependency>
  118. <!–工具类–>
  119. <dependency>
  120. <groupId>org.apache.commons</groupId>
  121. <artifactId>commons-lang3</artifactId>
  122. <version>3.8.1</version>
  123. </dependency>
  124. <!–google–>
  125. <!– https://mvnrepository.com/artifact/com.google.guava/guava –>
  126. <dependency>
  127. <groupId>com.google.guava</groupId>
  128. <artifactId>guava</artifactId>
  129. <version>30.0-jre</version>
  130. </dependency>
  131. <!– 工具类库 –>
  132. <dependency>
  133. <groupId>cn.hutool</groupId>
  134. <artifactId>hutool-core</artifactId>
  135. <version>5.5.0</version>
  136. </dependency>
  137. <!–lombok–>
  138. <dependency>
  139. <groupId>org.projectlombok</groupId>
  140. <artifactId>lombok</artifactId>
  141. <optional>true</optional>
  142. </dependency>
  143. <dependency>
  144. <groupId>org.springframework.boot</groupId>
  145. <artifactId>spring-boot-starter-test</artifactId>
  146. <scope>test</scope>
  147. </dependency>
  148. </dependencies>
  149. <build>
  150. <plugins>
  151. <plugin>
  152. <groupId>org.springframework.boot</groupId>
  153. <artifactId>spring-boot-maven-plugin</artifactId>
  154. </plugin>
  155. </plugins>
  156. </build>
  157. </project>

完整yml

  1. server:
  2. port: 8082
  3. #spring
  4. spring:
  5. devtools:
  6. restart:
  7. enabled: true
  8. main:
  9. allowbeandefinitionoverriding: true
  10. # mysql DATABASE CONFIG
  11. datasource:
  12. druid:
  13. filters: stat,wall,log4j2
  14. continueOnError: true
  15. type: com.alibaba.druid.pool.DruidDataSource
  16. url: jdbc:mysql://localhost:3306/mqttdb?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&allowPublicKeyRetrieval=true
  17. username: root
  18. password: 123456
  19. driverclassname: com.mysql.jdbc.Driver
  20. # see https://github.com/alibaba/druid
  21. initialSize: 15
  22. minIdle: 10
  23. maxActive: 200
  24. maxWait: 60000
  25. timeBetweenEvictionRunsMillis: 60000
  26. validationQuery: SELECT 1
  27. testWhileIdle: true
  28. testOnBorrow: false
  29. testOnReturn: false
  30. poolPreparedStatements: true
  31. keepAlive: true
  32. maxPoolPreparedStatementPerConnectionSize: 50
  33. connectionProperties:
  34. druid.stat.mergeSql: true
  35. druid.stat.slowSqlMillis: 5000
  36. shbykj:
  37. checkCrc: false
  38. #mybatis
  39. mybatisplus:
  40. mapperlocations: classpath:/mapper/*.xml
  41. typeAliasesPackage: org.spring.springboot.entity
  42. globalconfig:
  43. #主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
  44. idtype: 3
  45. #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
  46. fieldstrategy: 2
  47. #驼峰下划线转换
  48. dbcolumnunderline: true
  49. #刷新mapper 调试神器
  50. refreshmapper: true
  51. configuration:
  52. mapunderscoretocamelcase: true
  53. cacheenabled: false
  54. #logging
  55. logging:
  56. config: classpath:log4j2demo.xml

整合swaggerUi

pom

  1. <!–swagger api接口生成–>
  2. <dependency>
  3. <groupId>io.springfox</groupId>
  4. <artifactId>springfox-swagger-ui</artifactId>
  5. <version>2.9.2</version>
  6. </dependency>
  7. <!–解决报错:swagger:Illegal DefaultValue null for parameter type integer. java.lang.NumberFormatException: For input string: "".–>
  8. <!–1.5.21的AbstractSerializableParameter.getExample()方法增加了对空字符串的判断–>
  9. <dependency>
  10. <groupId>io.swagger</groupId>
  11. <artifactId>swagger-models</artifactId>
  12. <version>1.5.21</version>
  13. </dependency>
  14. <!– 代码生成器的依赖 –>
  15. <dependency>
  16. <groupId>io.springfox</groupId>
  17. <artifactId>springfox-swagger2</artifactId>
  18. <version>2.9.2</version>
  19. <exclusions>
  20. <exclusion>
  21. <groupId>com.google.guava</groupId>
  22. <artifactId>guava</artifactId>
  23. </exclusion>
  24. </exclusions>
  25. </dependency>

使用

  1. package com.shbykj.handle.web.wx;
  2. import com.baomidou.mybatisplus.core.metadata.IPage;
  3. import com.shbykj.handle.common.RetMsgData;
  4. import com.shbykj.handle.common.State;
  5. import com.shbykj.handle.common.model.sys.SysInstrument;
  6. import com.shbykj.handle.h.service.ISysInstrumentService;
  7. import io.swagger.annotations.Api;
  8. import io.swagger.annotations.ApiImplicitParam;
  9. import io.swagger.annotations.ApiImplicitParams;
  10. import io.swagger.annotations.ApiOperation;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.web.bind.annotation.GetMapping;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import org.springframework.web.bind.annotation.RestController;
  16. /**
  17. * 监测点接口
  18. *
  19. * @author
  20. * @date 2021-01-15 16:49
  21. */
  22. @RestController
  23. @RequestMapping({"/api/wxapoint"})
  24. @Api(
  25. tags = {"小程序 监测点接口"}
  26. )
  27. public class CSDevicesController extends BaseController {
  28. @Autowired
  29. private ISysInstrumentService sysInstrumentService;
  30. public CSDevicesController() {
  31. }
  32. @ApiOperation(
  33. value = "分页查询",
  34. notes = "分页查询站点信息"
  35. )
  36. @ApiImplicitParams({@ApiImplicitParam(
  37. name = "number",
  38. value = "设备编号",
  39. paramType = "query",
  40. dataType = "String"
  41. ), @ApiImplicitParam(
  42. name = "page",
  43. value = "页码 从1开始",
  44. required = false,
  45. dataType = "long",
  46. paramType = "query"
  47. ), @ApiImplicitParam(
  48. name = "size",
  49. value = "页数",
  50. required = false,
  51. dataType = "long",
  52. paramType = "query"
  53. )})
  54. @GetMapping({"/pageByNumber"})
  55. public RetMsgData<IPage<SysInstrument>> pageByNumber(@RequestParam(required = false) String number) {
  56. RetMsgData msg = new RetMsgData();
  57. try {
  58. IPage<SysInstrument> page1 = this.getPage();
  59. page1 = sysInstrumentService.pageByNumber(number, page1);
  60. msg.setData(page1);
  61. } catch (Exception var5) {
  62. msg.setState(State.RET_STATE_SYSTEM_ERROR);
  63. this.logger.error(var5.getMessage());
  64. }
  65. return msg;
  66. }
  67. }
  1. package com.shbykj.handle.common.model.sys;
  2. import com.baomidou.mybatisplus.annotation.IdType;
  3. import com.baomidou.mybatisplus.annotation.TableField;
  4. import com.baomidou.mybatisplus.annotation.TableId;
  5. import com.baomidou.mybatisplus.annotation.TableName;
  6. import io.swagger.annotations.ApiModel;
  7. import io.swagger.annotations.ApiModelProperty;
  8. import java.io.Serializable;
  9. import java.util.Date;
  10. @TableName("instrument")
  11. @ApiModel("仪器配置表字段信息")
  12. public class SysInstrument implements Serializable {
  13. private static final long serialVersionUID = 1L;
  14. @TableId(
  15. value = "id",
  16. type = IdType.AUTO
  17. )
  18. @ApiModelProperty(
  19. value = "id",
  20. name = "id",
  21. required = true
  22. )
  23. private Long id;
  24. @TableField("name")
  25. @ApiModelProperty(
  26. value = "名称 仪器名称",
  27. name = "name"
  28. )
  29. private String name;
  30. @TableField("number")
  31. @ApiModelProperty(
  32. value = "编号 仪器编号(PN)",
  33. name = "number"
  34. )
  35. private String number;
  36. @TableField("manufacturer")
  37. @ApiModelProperty(
  38. value = "生产厂商 生产厂商",
  39. name = "manufacturer"
  40. )
  41. private String manufacturer;
  42. @TableField("gmt_create")
  43. @ApiModelProperty(
  44. value = "创建时间",
  45. name = "gmt_create"
  46. )
  47. private Date gmtCreate;
  48. @TableField("gmt_modified")
  49. @ApiModelProperty(
  50. value = "更新时间",
  51. name = "gmt_modified"
  52. )
  53. private Date gmtModified;
  54. @TableField("is_deleted")
  55. @ApiModelProperty(
  56. value = "表示删除,0 表示未删除 默认0",
  57. name = "is_deleted"
  58. )
  59. private Integer isDeleted;
  60. @TableField("device_type")
  61. @ApiModelProperty(
  62. value = "设备类型(PT)",
  63. name = "device_type"
  64. )
  65. private String deviceType;
  66. public SysInstrument() {
  67. }
  68. public Long getId() {
  69. return this.id;
  70. }
  71. public String getName() {
  72. return this.name;
  73. }
  74. public String getNumber() {
  75. return this.number;
  76. }
  77. public String getManufacturer() {
  78. return this.manufacturer;
  79. }
  80. public Date getGmtCreate() {
  81. return this.gmtCreate;
  82. }
  83. public Date getGmtModified() {
  84. return this.gmtModified;
  85. }
  86. public Integer getIsDeleted() {
  87. return this.isDeleted;
  88. }
  89. public String getDeviceType() {
  90. return this.deviceType;
  91. }
  92. public void setId(final Long id) {
  93. this.id = id;
  94. }
  95. public void setName(final String name) {
  96. this.name = name;
  97. }
  98. public void setNumber(final String number) {
  99. this.number = number;
  100. }
  101. public void setManufacturer(final String manufacturer) {
  102. this.manufacturer = manufacturer;
  103. }
  104. public void setGmtCreate(final Date gmtCreate) {
  105. this.gmtCreate = gmtCreate;
  106. }
  107. public void setGmtModified(final Date gmtModified) {
  108. this.gmtModified = gmtModified;
  109. }
  110. public void setIsDeleted(final Integer isDeleted) {
  111. this.isDeleted = isDeleted;
  112. }
  113. public void setDeviceType(final String deviceType) {
  114. this.deviceType = deviceType;
  115. }
  116. public String toString() {
  117. return "SysInstrument(id=" + this.getId() + ", name=" + this.getName() + ", number=" + this.getNumber() + ", manufacturer=" + this.getManufacturer() + ", gmtCreate=" + this.getGmtCreate() + ", gmtModified=" + this.getGmtModified() + ", isDeleted=" + this.getIsDeleted() + ", deviceType=" + this.getDeviceType() + ")";
  118. }
  119. }

整合log4j

https://www.zzvips.com/article/152599.htm

MQTT 物联网系统基本架构

pom

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <parent>
  6. <groupId>org.springframework.boot</groupId>
  7. <artifactId>spring-boot-starter-parent</artifactId>
  8. <version>2.4.2</version>
  9. <relativePath/> <!– lookup parent from repository –>
  10. </parent>
  11. <groupId>com.shbykj</groupId>
  12. <artifactId>handle_mqtt</artifactId>
  13. <version>0.0.1-SNAPSHOT</version>
  14. <name>handle_mqtt</name>
  15. <description>Demo project for Spring Boot</description>
  16. <properties>
  17. <java.version>1.8</java.version>
  18. <skipTests>true</skipTests>
  19. </properties>
  20. <dependencies>
  21. <!–mqtt依赖–>
  22. <dependency>
  23. <groupId>org.springframework.boot</groupId>
  24. <artifactId>spring-boot-starter-integration</artifactId>
  25. </dependency>
  26. <dependency>
  27. <groupId>org.springframework.integration</groupId>
  28. <artifactId>spring-integration-stream</artifactId>
  29. </dependency>
  30. <dependency>
  31. <groupId>org.springframework.integration</groupId>
  32. <artifactId>spring-integration-mqtt</artifactId>
  33. </dependency>
  34. <dependency>
  35. <groupId>org.springframework.boot</groupId>
  36. <artifactId>spring-boot-starter-web</artifactId>
  37. <exclusions>
  38. <exclusion>
  39. <groupId>org.springframework.boot</groupId>
  40. <artifactId>spring-boot-starter-logging</artifactId>
  41. </exclusion>
  42. </exclusions>
  43. </dependency>
  44. <!–注意: <scope>compile</scope> 这里是正式环境,解决启动报错–>
  45. <!–idea springboot启动报SLF4J:Failed to load class “org.slf4j.impl.StaticLoggerBinder–>
  46. <!–参考:https://blog.csdn.net/u010696630/article/details/84991116–>
  47. <dependency>
  48. <groupId>org.slf4j</groupId>
  49. <artifactId>slf4j-simple</artifactId>
  50. <version>1.7.25</version>
  51. <scope>compile</scope>
  52. </dependency>
  53. <!– Log4j2 –>
  54. <dependency>
  55. <groupId>org.springframework.boot</groupId>
  56. <artifactId>spring-boot-starter-log4j2</artifactId>
  57. </dependency>
  58. <!– 排除 Spring-boot-starter 默认的日志配置 –>
  59. <dependency>
  60. <groupId>org.springframework.boot</groupId>
  61. <artifactId>spring-boot-starter</artifactId>
  62. <exclusions>
  63. <exclusion>
  64. <groupId>org.springframework.boot</groupId>
  65. <artifactId>spring-boot-starter-logging</artifactId>
  66. </exclusion>
  67. </exclusions>
  68. </dependency>
  69. <!–swagger api接口生成–>
  70. <dependency>
  71. <groupId>io.springfox</groupId>
  72. <artifactId>springfox-swagger-ui</artifactId>
  73. <version>2.9.2</version>
  74. </dependency>
  75. <!–解决报错:swagger:Illegal DefaultValue null for parameter type integer. java.lang.NumberFormatException: For input string: "".–>
  76. <!–1.5.21的AbstractSerializableParameter.getExample()方法增加了对空字符串的判断–>
  77. <dependency>
  78. <groupId>io.swagger</groupId>
  79. <artifactId>swagger-models</artifactId>
  80. <version>1.5.21</version>
  81. </dependency>
  82. <!– 代码生成器的依赖 –>
  83. <dependency>
  84. <groupId>io.springfox</groupId>
  85. <artifactId>springfox-swagger2</artifactId>
  86. <version>2.9.2</version>
  87. <exclusions>
  88. <exclusion>
  89. <groupId>com.google.guava</groupId>
  90. <artifactId>guava</artifactId>
  91. </exclusion>
  92. </exclusions>
  93. </dependency>
  94. <!–其他工具–>
  95. <!–devtools热部署–>
  96. <dependency>
  97. <groupId>org.springframework.boot</groupId>
  98. <artifactId>spring-boot-devtools</artifactId>
  99. <optional>true</optional>
  100. <scope>runtime</scope>
  101. </dependency>
  102. <!–json转换工具–>
  103. <dependency>
  104. <groupId>com.google.code.gson</groupId>
  105. <artifactId>gson</artifactId>
  106. </dependency>
  107. <!– redis –>
  108. <dependency>
  109. <groupId>org.springframework.boot</groupId>
  110. <artifactId>spring-boot-starter-data-redis</artifactId>
  111. </dependency>
  112. <!–工具类–>
  113. <dependency>
  114. <groupId>org.apache.commons</groupId>
  115. <artifactId>commons-lang3</artifactId>
  116. <version>3.8.1</version>
  117. </dependency>
  118. <!–google–>
  119. <!– https://mvnrepository.com/artifact/com.google.guava/guava –>
  120. <dependency>
  121. <groupId>com.google.guava</groupId>
  122. <artifactId>guava</artifactId>
  123. <version>30.0-jre</version>
  124. </dependency>
  125. <!– 工具类库 –>
  126. <dependency>
  127. <groupId>cn.hutool</groupId>
  128. <artifactId>hutool-core</artifactId>
  129. <version>5.5.0</version>
  130. </dependency>
  131. <!–lombok–>
  132. <dependency>
  133. <groupId>org.projectlombok</groupId>
  134. <artifactId>lombok</artifactId>
  135. <optional>true</optional>
  136. </dependency>
  137. <!–工具类–>
  138. <dependency>
  139. <groupId>commons-collections</groupId>
  140. <artifactId>commons-collections</artifactId>
  141. <version>3.2</version>
  142. </dependency>
  143. <dependency>
  144. <groupId>com.baomidou</groupId>
  145. <artifactId>spring-wind</artifactId>
  146. <version>1.1.5</version>
  147. <exclusions>
  148. <exclusion>
  149. <groupId>com.baomidou</groupId>
  150. <artifactId>mybatis-plus</artifactId>
  151. </exclusion>
  152. </exclusions>
  153. </dependency>
  154. <dependency>
  155. <groupId>com.baomidou</groupId>
  156. <version>3.1.2</version>
  157. <artifactId>mybatis-plus-boot-starter</artifactId>
  158. </dependency>
  159. <dependency>
  160. <groupId>mysql</groupId>
  161. <artifactId>mysql-connector-java</artifactId>
  162. <version>5.1.44</version>
  163. </dependency>
  164. <dependency>
  165. <groupId>com.alibaba</groupId>
  166. <artifactId>druid-spring-boot-starter</artifactId>
  167. <version>1.1.10</version>
  168. </dependency>
  169. <!–PageHelper分页插件–>
  170. <dependency>
  171. <groupId>com.github.pagehelper</groupId>
  172. <artifactId>pagehelper-spring-boot-starter</artifactId>
  173. <version>1.2.12</version>
  174. </dependency>
  175. <dependency>
  176. <groupId>org.springframework.boot</groupId>
  177. <artifactId>spring-boot-starter-test</artifactId>
  178. <scope>test</scope>
  179. </dependency>
  180. </dependencies>
  181. <build>
  182. <plugins>
  183. <plugin>
  184. <groupId>org.springframework.boot</groupId>
  185. <artifactId>spring-boot-maven-plugin</artifactId>
  186. <executions>
  187. <execution>
  188. <goals>
  189. <goal>repackage</goal>
  190. </goals>
  191. </execution>
  192. </executions>
  193. </plugin>
  194. </plugins>
  195. </build>
  196. </project>

yml

  1. server:
  2. port: 8082
  3. iot:
  4. mqtt:
  5. clientId: ${random.value}
  6. defaultTopic: topic
  7. shbykjTopic: shbykj_topic
  8. url: tcp://127.0.0.1:1883
  9. username: admin
  10. password: admin
  11. completionTimeout: 3000
  12. #微信小程序相关参数
  13. shbykjWeixinAppid: wxae343ca8948f97c4
  14. shbykjSecret: 9e168c92702efc06cb12fa22680f049a
  15. #spring
  16. spring:
  17. devtools:
  18. restart:
  19. enabled: true
  20. main:
  21. allowbeandefinitionoverriding: true
  22. # mysql DATABASE CONFIG
  23. datasource:
  24. druid:
  25. filters: stat,wall,log4j2
  26. continueOnError: true
  27. type: com.alibaba.druid.pool.DruidDataSource
  28. url: jdbc:mysql://localhost:3306/mqttdb?useSSL=false&useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC&allowPublicKeyRetrieval=true
  29. username: root
  30. password: 123456
  31. driverclassname: com.mysql.jdbc.Driver
  32. # see https://github.com/alibaba/druid
  33. initialSize: 15
  34. minIdle: 10
  35. maxActive: 200
  36. maxWait: 60000
  37. timeBetweenEvictionRunsMillis: 60000
  38. validationQuery: SELECT 1
  39. testWhileIdle: true
  40. testOnBorrow: false
  41. testOnReturn: false
  42. poolPreparedStatements: true
  43. keepAlive: true
  44. maxPoolPreparedStatementPerConnectionSize: 50
  45. connectionProperties:
  46. druid.stat.mergeSql: true
  47. druid.stat.slowSqlMillis: 5000
  48. shbykj:
  49. checkCrc: false
  50. #mybatis
  51. mybatisplus:
  52. mapperlocations: classpath:/mapper/*.xml
  53. typeAliasesPackage: org.spring.springboot.entity
  54. globalconfig:
  55. #主键类型 0:"数据库ID自增", 1:"用户输入ID",2:"全局唯一ID (数字类型唯一ID)", 3:"全局唯一ID UUID";
  56. idtype: 3
  57. #字段策略 0:"忽略判断",1:"非 NULL 判断"),2:"非空判断"
  58. fieldstrategy: 2
  59. #驼峰下划线转换
  60. dbcolumnunderline: true
  61. #刷新mapper 调试神器
  62. refreshmapper: true
  63. configuration:
  64. mapunderscoretocamelcase: true
  65. cacheenabled: false
  66. #log4j打印sql日志
  67. logimpl: org.apache.ibatis.logging.stdout.StdOutImpl
  68. #logging
  69. logging:
  70. config: classpath:log4j2demo.xml

到此这篇关于springboot 实现mqtt物联网的文章就介绍到这了,更多相关springboot 实现mqtt物联网内容请搜索快网idc以前的文章或继续浏览下面的相关文章希望大家以后多多支持快网idc!

原文链接:https://blog.csdn.net/weixin_44106334/article/details/112658337

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 springboot 实现mqtt物联网的示例代码 https://www.kuaiidc.com/106855.html

相关文章

发表评论
暂无评论