我有一个Spring-boot项目,可以扫描文件夹并使用元数据中的关键字为所有找到的照片建立索引。
我具有下一个结构:
java
de.stadt
controllers
entitys
repository
services
ImageService
tools
ImageProcessing
ScanDirs
当我尝试使用ImageService的RecursiveTask调用Tools类ScanDirs时 我有java.lang.NullPointerException:null 将数据推送到构造ScanDirs的权利如何?
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.util.concurrent.ForkJoinTask.getThrowableException(ForkJoinTask.java:598)
at java.util.concurrent.ForkJoinTask.reportException(ForkJoinTask.java:677)
at java.util.concurrent.ForkJoinTask.join(ForkJoinTask.java:720)
at java.util.concurrent.ForkJoinPool.invoke(ForkJoinPool.java:2616)
at de.stadt.presse.service.ImageService.callScanDirsToolsClass(ImageService.java:67)
ImageService.class:
@Service
public class ImageService {
@Autowired
private ImageRepository imageRepository;
@Autowired
private KeywordsService keywordsService;
@Autowired
private ScanDirs task;
private static final int AVAILABLE_PROCESSORS = Runtime.getRuntime().availableProcessors();
private final ForkJoinPool pool = new ForkJoinPool(AVAILABLE_PROCESSORS);
public boolean callScanDirsToolsClass(String folderPath, String thumpPath, String googleVisionLocalPath,
int scaleHeight, int scaleHeightForGoogleVision, String strText) {
task = new ScanDirs(folderPath, thumpPath, googleVisionLocalPath, scaleHeight,
scaleHeightForGoogleVision, strText); //<-----------------if pusching the data here false . how right to push the data to the constructur ?
final Boolean result = pool.invoke(task);
System.out.println(result);
return true;
}
}
ScanDirs.class看起来像:
@Service
@NoArgsConstructor
public class ScanDirs extends RecursiveTask<Boolean> {
@Autowired
private ImageService imageService;
@Autowired
private KeywordsService keywordsService;
...
public ScanDirs(String folder, String thum........) {
...
}
@Override
protected Boolean compute() {
Image image = imageService.findByImagePath(file.getPath());
...
}