package com.chinaztt.mes.docx.config;
|
|
import com.chinaztt.mes.docx.handler.SerialPortListener;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.boot.ApplicationArguments;
|
import org.springframework.boot.ApplicationRunner;
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
import org.springframework.stereotype.Component;
|
|
import javax.annotation.Resource;
|
|
/**
|
* 项目启动完成后执行串口监听
|
*/
|
@Slf4j
|
@Component
|
public class SerialPortStartupRunner implements ApplicationRunner {
|
|
@Value("${serialPort.enable}")
|
public Boolean enableSerialPort;
|
|
@Resource
|
private SerialPortListener serialPortListenerService;
|
|
@Autowired
|
private ThreadPoolTaskExecutor threadPoolTaskExecutor;
|
|
@Override
|
public void run(ApplicationArguments args) {
|
log.info("===== SpringBoot 项目启动完成,开始初始化串口监听 =====");
|
// 启动串口监听(核心调用)
|
if(enableSerialPort)threadPoolTaskExecutor.execute(() -> serialPortListenerService.serialPortDataListener());
|
}
|
}
|