当前位置: 首页 > news >正文

【问题解决】本地方法部署环境不存在的问题(投机取巧方法)

文章目录

    • 0.问
    • 1.怀疑pom有深层的依赖冲突。
    • 2.问题解决

0.问

ps:急就直接看2.问题解决

一个方法,本地可以跑,但是放到部署环境就无法跑,报错方法不存在。

org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchMethodError: com.itextpdf.text.Image.scaleToFit(Lcom/itextpdf/text/Rectangle;)V

解决思路:

1.怀疑pom有深层的依赖冲突。

1、执行 mvn dependency:tree -Dverbose
2、在有依赖的包下面加上排除

<exclusions><exclusion><artifactId>com.itextpdf</artifactId><groupId>itextpdf</groupId></exclusion>
<exclusions>

3、重试,没用!谢特。应该不是依赖版本冲突。
排除类冲突,应该也不是方法不存在,如果真是方法不存在,那么构建就会出问题,但是jar包构建没有出问题,能正常启动。
4、下载部署环境的依赖jar包,检查类方法都存在,且版本一致。

2.问题解决

在线上环境打印类里面所有的方法,找一个可以用的
还真被我找到一个重载的方法

private static void log() {String className = "com.itextpdf.text.Image";String methodName = "scaleToFit";Class<?>[] parameterTypes = {com.itextpdf.text.Rectangle.class};try {Class<?> clazz = Class.forName(className);// Check versionPackage pkg = clazz.getPackage();if (pkg != null) {String implementationVersion = pkg.getImplementationVersion();String specificationVersion = pkg.getSpecificationVersion();log.info("[getPdfWatermarkImageLog] Implementation Version: {}", implementationVersion);log.info("[getPdfWatermarkImageLog] Specification Version: {}", specificationVersion);} else {log.info("[getPdfWatermarkImageLog] Package information is not available.");}// Check methodsMethod[] methods = clazz.getDeclaredMethods();for (Method method : methods) {log.info("[getPdfWatermarkImageLog] Method: {}, name:{}, parameterTypes:{}", method, method.getName(), method.getParameterTypes());}// Check if a specific method existstry {Method specificMethod = clazz.getDeclaredMethod(methodName, parameterTypes);log.info("[getPdfWatermarkImageLog] Method :{} (Rectangle) exists. :{}", methodName, specificMethod);} catch (NoSuchMethodException e) {log.info("[getPdfWatermarkImageLog] Method {} (Rectangle) does not exist.", methodName);}} catch (ClassNotFoundException e) {log.error("[getPdfWatermarkImageLog] Class not found: {}", className, e);}}

果然,方法不存在,但是有另一个可以替代的
日志1: [getPdfWatermarkImageLog] Method scaleToFit(Rectangle) does not exist.
日志2:[getPdfWatermarkImageLog] Method: public void com.itextpdf.text.Image.scaleToFit(float,float), name:scaleToFit, parameterTypes:[float, float]

偷鸡解决。


http://www.mrgr.cn/news/9407.html

相关文章:

  • Sentinel-1 Level 1数据处理的详细算法定义(六)
  • 暑期算法训练
  • 【生日视频制作】教师节中秋节国庆节奔驰大G汽车车身AE模板修改文字软件生成器教程特效素材【AE模板】
  • Android 10.0 系统默认打开的TP触摸开关功能实现
  • 解锁C#性能监控:内置性能计数器全解析
  • vue export的用法
  • Git的使用教程及常用语法03
  • 华为数通方向HCIP-DataCom H12-821题库(更新单选真题:1-10)
  • 【0317】Postgres内核之VACUUM (FULL)通用 utility function invoker (12)
  • 五、Centos7-安装Jenkins
  • 【Nature】在科研中应用ChatGPT:如何与数据对话
  • JS中【map】知识点和用法介绍
  • OpenCV几何图像变换(8)调整图像大小的函数resize()的使用
  • 公考面试笔记_社会现象类1
  • P(查准率) R(查全率) AP mAP最通俗准确的讲解
  • 网络安全售前入门01——产品了解
  • 调度中心控制台的重要性体现在哪些方面
  • 爆改YOLOv8 | 利用MB-TaylorFormer提高YOLOv8图像去雾检测
  • 文心快码助力项目实战开发
  • 爆改YOLOv8 |利用 iAFF迭代注意力改进C2f,高效涨点