update 使用依赖注入 注册convert对象

(cherry picked from commit b77fcacc8f2c00ec204b69a63f1daa0a64d1166c)
V0.5.x
jay 2023-02-26 20:49:17 +08:00
parent 63a905c01f
commit 33a5c3cfba
2 changed files with 16 additions and 3 deletions

View File

@ -12,6 +12,7 @@ package cc.iotkit.comps;
import cc.iotkit.common.ComponentClassLoader;
import cc.iotkit.common.exception.BizException;
import cc.iotkit.common.thing.ThingService;
import cc.iotkit.common.utils.JsonUtil;
import cc.iotkit.comp.CompConfig;
import cc.iotkit.comp.IComponent;
@ -21,8 +22,8 @@ import cc.iotkit.comps.config.ComponentConfig;
import cc.iotkit.comps.service.DeviceBehaviourService;
import cc.iotkit.converter.Device;
import cc.iotkit.converter.DeviceMessage;
import cc.iotkit.converter.ScriptConverter;
import cc.iotkit.common.thing.ThingService;
import cc.iotkit.converter.GraalJsScriptConverter;
import cc.iotkit.converter.IConverter;
import cc.iotkit.data.IDeviceInfoData;
import cc.iotkit.data.IProductData;
import cc.iotkit.data.IProtocolComponentData;
@ -71,6 +72,12 @@ public class DeviceComponentManager {
@Autowired
private DeviceRouter deviceRouter;
private final IConverter scriptConverter;
public DeviceComponentManager(IConverter converter) {
this.scriptConverter = converter;
}
@PostConstruct
public void init() {
List<ProtocolComponent> componentList = protocolComponentData.findByStateAndType(
@ -102,7 +109,6 @@ public class DeviceComponentManager {
componentInstance.create(new CompConfig(300, component.getConfig()));
try {
ScriptConverter scriptConverter = new ScriptConverter();
Path converterPath = componentConfig.getConverterFilePath(component.getConverter());
String converterScript = FileUtils.readFileToString(converterPath.
resolve(ProtocolConverter.SCRIPT_FILE_NAME).toFile(), "UTF-8");

View File

@ -1,5 +1,7 @@
package cc.iotkit.comps.config;
import cc.iotkit.converter.GraalJsScriptConverter;
import cc.iotkit.converter.IConverter;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import lombok.Data;
@ -36,4 +38,9 @@ public class ComponentConfig {
}
@Bean
public IConverter scriptConverter(){
return new GraalJsScriptConverter();
}
}