fix: refresh ImageIO plugins before PDF conversion

This commit is contained in:
kl
2026-08-11 12:54:50 +08:00
parent e134689df3
commit 257180eb95
2 changed files with 62 additions and 1 deletions

View File

@@ -18,6 +18,7 @@ import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.ObjectUtils;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
@@ -93,6 +94,8 @@ public class PdfToJpgService {
@PostConstruct
public void init() {
refreshImageIoPlugins();
int maxThreads = ConfigConstants.getPdfMaxThreads();
// 使用固定大小的虚拟线程池
this.virtualThreadExecutor = Executors.newFixedThreadPool(maxThreads,
@@ -104,6 +107,13 @@ public class PdfToJpgService {
scheduleCacheCleanup();
}
static void refreshImageIoPlugins() {
// ImageIO only scans once automatically. If another launcher or Java agent initializes
// it before Spring Boot installs its application class loader, nested JAR providers such
// as jbig2-imageio remain invisible until the application class path is scanned again.
ImageIO.scanForPlugins();
}
@PreDestroy
public void shutdown() {
logger.info("开始关闭PDF转换服务...");
@@ -852,4 +862,4 @@ public class PdfToJpgService {
}
}
}