|
|
|
|
@ -2,12 +2,12 @@ package com.rehome.mqttclienttemperature;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.rehome.mqttclienttemperature.service.TemperatureService;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.BeansException;
|
|
|
|
|
import org.springframework.boot.CommandLineRunner;
|
|
|
|
|
import org.springframework.boot.SpringApplication;
|
|
|
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
|
|
import org.springframework.boot.builder.SpringApplicationBuilder;
|
|
|
|
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
|
|
|
|
import org.springframework.context.ApplicationContext;
|
|
|
|
|
import org.springframework.context.ApplicationContextAware;
|
|
|
|
|
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
|
|
|
|
|
@ -16,14 +16,13 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
|
|
|
|
|
|
@EnableJpaAuditing
|
|
|
|
|
@EnableScheduling
|
|
|
|
|
@EnableAsync
|
|
|
|
|
@SpringBootApplication
|
|
|
|
|
public class AdminClientTemperatureApplication extends SpringBootServletInitializer implements CommandLineRunner, ApplicationContextAware {
|
|
|
|
|
public class AdminClientTemperatureApplication implements CommandLineRunner, ApplicationContextAware {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取Spring框架的上下文
|
|
|
|
|
@ -48,17 +47,17 @@ public class AdminClientTemperatureApplication extends SpringBootServletInitiali
|
|
|
|
|
//在这里可以调用applicationContext了
|
|
|
|
|
Map<String, Object> controllers = applicationContext.getBeansWithAnnotation(RequestMapping.class);
|
|
|
|
|
for (Map.Entry<String, Object> entry : controllers.entrySet()) {
|
|
|
|
|
log.info("------------------------");
|
|
|
|
|
log.info(entry.getKey());//demo1Controller
|
|
|
|
|
System.out.println("------------------------");
|
|
|
|
|
System.out.println(entry.getKey());//demo1Controller
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
if (temperatureService != null) {
|
|
|
|
|
log.info("------------------------");
|
|
|
|
|
log.info("TemperatureController is not empty");
|
|
|
|
|
System.out.println("------------------------");
|
|
|
|
|
System.out.println("TemperatureController is not empty");
|
|
|
|
|
MqttRSAClient client = new MqttRSAClient();
|
|
|
|
|
client.start(temperatureService);
|
|
|
|
|
}else {
|
|
|
|
|
log.info("temperatureService is empty");
|
|
|
|
|
System.out.println("temperatureService is empty");
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
ex.printStackTrace();
|
|
|
|
|
@ -69,14 +68,4 @@ public class AdminClientTemperatureApplication extends SpringBootServletInitiali
|
|
|
|
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
|
|
|
|
this.applicationContext = applicationContext;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @date 2021-05-18 09:20
|
|
|
|
|
* @description: 容器配置,springboot打war包布署必须添加这个配置 为了打包springboot项目
|
|
|
|
|
* @Param: SpringApplicationBuilder
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
|
|
|
|
|
return builder.sources(AdminClientTemperatureApplication.class);
|
|
|
|
|
}
|
|
|
|
|
}
|