Docker容器中@Async方法生成POI Excel遇UnsatisfiedLinkError求助
问题:异步生成Excel时出现UnsatisfiedLinkError依赖缺失问题
我使用Apache POI编写异步代码生成Excel报表,仅在标注@Async的方法执行时抛出java.lang.UnsatisfiedLinkError异常,非异步方法可正常生成Excel。错误信息显示JDK路径下的/opt/jdk/17.0_10l64/lib/libfontmanager.so依赖的libfreetype.so.6无法找到。已在pom.xml中添加maven-surefire-plugin相关配置,但问题未解决。服务器为Red Hat Enterprise Linux 8.9,无法自行安装软件,需向运维团队申请安装什么?
相关代码片段
@Configuration @EnableAsync public class ReportingActionAsynch { //Apache poi code to generate excel report }
错误日志
ERROR [pool-9-thread-1] .a.i.SimpleAsyncUncaughtExceptionHandler o.s.a.i.SimpleAsyncUncaughtExceptionHandler.handleUncaughtException(SimpleAsyncUncaughtExceptionHandler.java:39) - POST|/report/generateReport|||||||||||||--|Unexpected exception occurred invoking async method: public void com.action.ReportingActionAsynch.run(com.reporting.model.ReportingModel,com.dao.ReportingDAO,com.action.ReportingAction,com.action.DeckReportAction,com.models.LoginModelBean): java.lang.UnsatisfiedLinkError: /opt/jdk/17.0_10l64/lib/libfontmanager.so: libfreetype.so.6: cannot open shared object file: No such file or directory at java.base/jdk.internal.loader.NativeLibraries.load(Native Method) ...
pom.xml配置
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>true</skipTests> <reportsDirectory>target/surefire-reports</reportsDirectory> <failIfNoTests>true</failIfNoTests> <testFailureIgnore>true</testFailureIgnore> <argLine>--add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/jdk.internal=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.xml/jdk.xml.internal=ALL-UNNAMED --add-opens java.base/java.nio.charset=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java.nio.file=ALL-UNNAMED --add-opens java.base/sun.nio.fs=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.base/java.time=ALL-UNNAMED --add-opens java.base/java.util.stream=ALL-UNNAMED --add-opens java.base/java.util.regex=ALL-UNNAMED --add-opens java.base/java.security=ALL-UNNAMED</argLine> </configuration> </plugin>
服务器环境信息
NAME="Red Hat Enterprise Linux" VERSION="8.9 (Ootpa)" ID="rhel" ID_LIKE="fedora" VERSION_ID="8.9" PLATFORM_ID="platform:el8"
解决方案
需要向运维团队申请安装freetype包(RHEL 8.9下包名为freetype),该包会提供缺失的libfreetype.so.6库文件。
补充说明
异步场景才触发问题的原因是:主线程可能在之前的操作中已间接加载过相关依赖库,而异步线程首次执行Excel生成的字体相关操作时,才会尝试加载libfontmanager.so,进而触发对libfreetype.so.6的依赖检查,因此仅异步方法暴露该缺失问题。
内容的提问来源于stack exchange,提问作者Pat
相关产品推荐
相关产品推荐

