标题## SpringBoot+OpenCV 调用报错: Imgcodecs.imread_1(Ljava/lang/String;)J]
情况:再Test跟main方法做过测试以后准备封装到接口里面使用,一调用就报错
util代码如下
public static Map<String,Object> fileSacnningQuality(String path){
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Map<String,Object> resuleMap=new HashMap();
Mat src = Imgcodecs.imread(path);
}
controller测试代码如下
@GetMapping("/fileSacnningQualityUtiltest")
public void test(){
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
System.load("D:/software/OpenCv/opencv/build/java/x64/opencv_java341.dll");
File f=new File ("D:/Users/Administrator/Desktop/0");
File[] files = f.listFiles();
for(int i=0;i<files.length;i++){
if(files[i].getPath().contains(".png") && !files[i].getPath().contains("年") ){
Mat src = Imgcodecs.imread(files[i].getPath());
ScannerWartQuality scannerWartQuality=new ScannerWartQuality();
scannerWartQuality.setPath(files[i].getPath());
int i1 = scannerWartQualityService.addScannerWartQuality(scannerWartQuality);
}
/*ScannerWartQuality s=new ScannerWartQuality();
JsonObject j=new JsonObject();
j.addProperty("path",files[i].getPath());
//队列
jmsMessagingTemplate.convertAndSend("fileSacnningQualityUtil",j.toString());*/
}
}
运行结果:
根据网上的资料找了两种解决方法,对我来说第二种方法成功解决问题,第一种方法卧病没有成功,我将两种方法都贴上
方法一:删除pom的热部署依赖
org.springframework
springloaded
org.springframework.boot
spring-boot-devtools
原文地址:http://t.csdn.cn/Iqy0s
方法二:删掉devtools依赖或者在启动类加上System.setProperty(“spring.devtools.restart.enabled”, “false”);
public static void main(String[] args) throws Exception {
System.setProperty("spring.devtools.restart.enabled", "false");
ConfigurableApplicationContext content = SpringApplication.run(FileServerApplication.class,args);
}
原文地址:http://t.csdn.cn/KNRMa
根据第二种方式,完美解决问题,也可以看看作者原创