package cn.exrick.xboot.your.util; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.ApplicationArguments; import org.springframework.boot.ApplicationRunner; import org.springframework.stereotype.Component; @Component public class ApplicationRunnerImpl implements ApplicationRunner { @Autowired private HaiKangPost haiKangPost; @Autowired private MQTT mqtt; @Override public void run(ApplicationArguments args) throws Exception { String topicInfo = haiKangPost.getTopicInfo(); System.out.println("订阅信息:"+topicInfo); JSONObject jsonObject = JSONUtil.parseObj(topicInfo); if(jsonObject.get("data")!=null){ String data = jsonObject.get("data").toString(); JSONObject jsonObject2 = JSONUtil.parseObj(data); String clientId = jsonObject2.get("clientId").toString(); String userName = jsonObject2.get("userName").toString(); String password = jsonObject2.get("password").toString(); mqtt.event(clientId,userName,password); } } }