跳转到主内容
websoft网络软件专家 - 深耕网络技术,打造实用软件!

SpringBoot JAR包瘦身导致启动时提示IllegalAccessError?如何解决?

springboot jar包瘦身后启动提示 illegalaccesserror ? 在对 spring boot 应用进行瘦身后,启动 jar 包时可能会遇到 java.lang.illegalaccesserror 错误,具体表现为 class org.springframework.cloud.openfeign.hystrixtargeter$$enhancerbyspringcglib$$7e887a8a cannot access its superclass org.springframework.cloud.openfeign.hystrixtargeter。 这通常是由在瘦身后的 classloader 中获取父类时出现不一致造成的。具体原因可能是: 使用了 spring boot devtools,但项目本身未依赖该 jar。 在 manifest.mf 添加了 class-path 参数,指定瘦身 jar 之外的依赖库。 解决方案: Apache 2.4.62 PHP中文网提供Apache 2.4.62 官方 tar.gz 源码包下载,通过源码编译安装,开发者能够灵活定制模块、优化性能并精准控制安装路径,满足多样化的业务需求。 下载 一种临时的解决方法是通过自定义 beanpostprocessor 来还原 classloader,但这只是治标不治本。 永久的解决方案是: 移除 spring boot maven 插件: org.springframework.boot:spring-boot-maven-plugin。 在 maven dependency 插件中添加 main-class 和 outputdirectory:
org.apache.maven.plugins maven-jar-plugin true lib/ false com.example.Application ${project.build.directory}/boot-jar
完成以上修改后,即可解决 illegalaccesserror 错误,实现 jar 包瘦身。

相关文章