2
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
package com.example.demo.barcode;
|
||||
|
||||
import jakarta.annotation.PreDestroy;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class PythonBarcodeAutoStarter implements ApplicationRunner {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(PythonBarcodeAutoStarter.class);
|
||||
private final PythonBarcodeProcessManager manager;
|
||||
private final PythonBarcodeProperties properties;
|
||||
|
||||
public PythonBarcodeAutoStarter(PythonBarcodeProcessManager manager, PythonBarcodeProperties properties) {
|
||||
this.manager = manager;
|
||||
this.properties = properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) {
|
||||
if (!properties.isEnabled()) {
|
||||
log.info("Python 条码识别服务未启用 (python.barcode.enabled=false)");
|
||||
return;
|
||||
}
|
||||
log.info("启动 Python 条码识别服务...");
|
||||
manager.startIfEnabled();
|
||||
log.info("Python 条码识别服务已就绪");
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
public void onShutdown() {
|
||||
if (properties.isEnabled()) {
|
||||
log.info("停止 Python 条码识别服务...");
|
||||
manager.stopIfRunning();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user