Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

refactor: support extending jar directories for plugin class loader #3108

Merged
merged 3 commits into from
Jan 9, 2023

Conversation

guqing
Copy link
Member

@guqing guqing commented Jan 6, 2023

What type of PR is this?

/kind improvement
/area core
/milestone 2.2.x

What this PR does / why we need it:

修复引入外部依赖的插件以开发模式启动时会出现 NoClassDefFoundError 的问题
see #3107 for more detail.

Which issue(s) this PR fixes:

Fixes #3107

Special notes for your reviewer:

how to test it?
以插件 development 模式启动以下两个插件观察是否正常启动:

期望没有 Caused by: java. lang. NoClassDefFoundEenon 错误,且插件正确启动。

/cc @halo-dev/sig-halo

Does this PR introduce a user-facing change?

修复引入外部依赖的插件以开发模式启动时会出现 NoClassDefFoundError 的问题

@f2c-ci-robot f2c-ci-robot bot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Jan 6, 2023
@f2c-ci-robot f2c-ci-robot bot added this to the 2.2.x milestone Jan 6, 2023
@f2c-ci-robot f2c-ci-robot bot added kind/improvement Categorizes issue or PR as related to a improvement. area/core Issues or PRs related to the Halo Core labels Jan 6, 2023
@ruibaby
Copy link
Member

ruibaby commented Jan 8, 2023

image

我这里依然无法启动,日志:

2023-01-08T21:18:48.996+08:00 ERROR 13737 --- [nReconciler-t-1] run.halo.app.plugin.HaloPluginManager    : Unable to start plugin 'PluginS3ObjectStorage@1.2.1-SNAPSHOT'

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'run.halo.s3os.S3OsAttachmentHandler': Lookup method resolution failed
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.checkLookupMethods(AutowiredAnnotationBeanPostProcessor.java:470) ~[spring-beans-6.0.3.jar:6.0.3]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:340) ~[spring-beans-6.0.3.jar:6.0.3]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1283) ~[spring-beans-6.0.3.jar:6.0.3]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1185) ~[spring-beans-6.0.3.jar:6.0.3]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:561) ~[spring-beans-6.0.3.jar:6.0.3]
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521) ~[spring-beans-6.0.3.jar:6.0.3]
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[spring-beans-6.0.3.jar:6.0.3]
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.0.3.jar:6.0.3]
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[spring-beans-6.0.3.jar:6.0.3]
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.0.3.jar:6.0.3]
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:961) ~[spring-beans-6.0.3.jar:6.0.3]
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:915) ~[spring-context-6.0.3.jar:6.0.3]
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:584) ~[spring-context-6.0.3.jar:6.0.3]
	at run.halo.app.plugin.PluginApplicationInitializer.initApplicationContext(PluginApplicationInitializer.java:105) ~[main/:na]
	at run.halo.app.plugin.PluginApplicationInitializer.onStartUp(PluginApplicationInitializer.java:121) ~[main/:na]
	at run.halo.app.plugin.HaloPluginManager.doStartPlugin(HaloPluginManager.java:255) ~[main/:na]
	at run.halo.app.plugin.HaloPluginManager.startPlugin(HaloPluginManager.java:211) ~[main/:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.lambda$startPlugin$4(PluginReconciler.java:142) ~[main/:na]
	at java.base/java.util.Optional.ifPresent(Optional.java:178) ~[na:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.startPlugin(PluginReconciler.java:139) ~[main/:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.reconcilePluginState(PluginReconciler.java:114) ~[main/:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.lambda$reconcile$0(PluginReconciler.java:64) ~[main/:na]
	at java.base/java.util.Optional.ifPresent(Optional.java:178) ~[na:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.reconcile(PluginReconciler.java:58) ~[main/:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.reconcile(PluginReconciler.java:42) ~[main/:na]
	at run.halo.app.extension.controller.DefaultController$Worker.run(DefaultController.java:163) ~[main/:na]
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[na:na]
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
	at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
Caused by: java.lang.IllegalStateException: Failed to introspect Class [run.halo.s3os.S3OsAttachmentHandler] from ClassLoader [org.pf4j.PluginClassLoader@655a866b]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:483) ~[spring-core-6.0.3.jar:6.0.3]
	at org.springframework.util.ReflectionUtils.doWithLocalMethods(ReflectionUtils.java:320) ~[spring-core-6.0.3.jar:6.0.3]
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.checkLookupMethods(AutowiredAnnotationBeanPostProcessor.java:448) ~[spring-beans-6.0.3.jar:6.0.3]
	... 30 common frames omitted
Caused by: java.lang.NoClassDefFoundError: com/amazonaws/auth/AWSCredentials
	at java.base/java.lang.Class.getDeclaredMethods0(Native Method) ~[na:na]
	at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3402) ~[na:na]
	at java.base/java.lang.Class.getDeclaredMethods(Class.java:2504) ~[na:na]
	at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:465) ~[spring-core-6.0.3.jar:6.0.3]
	... 32 common frames omitted
Caused by: java.lang.ClassNotFoundException: com.amazonaws.auth.AWSCredentials
	at org.pf4j.PluginClassLoader.loadClass(PluginClassLoader.java:144) ~[pf4j-3.8.0.jar:3.8.0]
	... 36 common frames omitted

2023-01-08T21:18:48.997+08:00 DEBUG 13737 --- [nReconciler-t-1] r.h.app.plugin.SpringComponentsFinder    : Removing components storage from cache [PluginS3ObjectStorage].
2023-01-08T21:18:48.997+08:00 ERROR 13737 --- [nReconciler-t-1] r.h.a.e.controller.DefaultController     : Reconciler in run.halo.app.core.extension.reconciler.PluginReconciler-worker-1 aborted with an error, re-enqueuing...

org.pf4j.PluginRuntimeException: Error creating bean with name 'run.halo.s3os.S3OsAttachmentHandler': Lookup method resolution failed
	at run.halo.app.core.extension.reconciler.PluginReconciler.handleStatus(PluginReconciler.java:195) ~[main/:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.lambda$startPlugin$4(PluginReconciler.java:143) ~[main/:na]
	at java.base/java.util.Optional.ifPresent(Optional.java:178) ~[na:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.startPlugin(PluginReconciler.java:139) ~[main/:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.reconcilePluginState(PluginReconciler.java:114) ~[main/:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.lambda$reconcile$0(PluginReconciler.java:64) ~[main/:na]
	at java.base/java.util.Optional.ifPresent(Optional.java:178) ~[na:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.reconcile(PluginReconciler.java:58) ~[main/:na]
	at run.halo.app.core.extension.reconciler.PluginReconciler.reconcile(PluginReconciler.java:42) ~[main/:na]
	at run.halo.app.extension.controller.DefaultController$Worker.run(DefaultController.java:163) ~[main/:na]
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539) ~[na:na]
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[na:na]
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[na:na]
	at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]

@guqing
Copy link
Member Author

guqing commented Jan 8, 2023

image

我这里依然无法启动,日志:

你有配置了什么多余的配置吗,比如做了如下配置:
image
但是 lib-directories 的目录配置的不对之类的,lib-directories 默认就是 build/libs,不需要配置否则会覆盖默认值

@JohnNiang
Copy link
Member

这个问题是 @pannanxu 首次发现的,请问 @pannanxu 这个修复能解决多模块的问题么?

@guqing
Copy link
Member Author

guqing commented Jan 9, 2023

image

我这里依然无法启动,日志:

dev profile 的 lib-directories 配置有点问题,我更新了,参考 de8489e

Copy link
Member

@ruibaby ruibaby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

image

/lgtm

@f2c-ci-robot f2c-ci-robot bot added the lgtm Indicates that a PR is ready to be merged. label Jan 9, 2023
@pannanxu
Copy link

pannanxu commented Jan 9, 2023

目前我测试的三个插件是可以启动成功的

image

接口调用也是没问题

image

配置如下

image

这个问题是 @pannanxu 首次发现的,请问 @pannanxu 这个修复能解决多模块的问题么?

Copy link
Member

@JohnNiang JohnNiang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/approve

@f2c-ci-robot
Copy link

f2c-ci-robot bot commented Jan 9, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JohnNiang

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@f2c-ci-robot f2c-ci-robot bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 9, 2023
@f2c-ci-robot f2c-ci-robot bot merged commit 64ed793 into halo-dev:main Jan 9, 2023
@guqing guqing deleted the refactor/3107 branch January 9, 2023 09:42
@ruibaby ruibaby modified the milestones: 2.2.x, 2.2.0 Jan 12, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/core Issues or PRs related to the Halo Core kind/improvement Categorizes issue or PR as related to a improvement. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

使用了外部依赖的插件在开发模式下出现 NoClassDefFoundError 问题
4 participants