sermant-io / Sermant

CNCF sandbox project, a Cloud-Native Proxyless Service Mesh based on Java Bytecode Enhancement Technology
https://sermant.io/
Apache License 2.0
1.25k stars 164 forks source link

关于ClassInjectDefine中factoryName为空的问题 #1596

Closed AYue-94 closed 2 months ago

AYue-94 commented 3 months ago

What do you want to ask?

image

  1. 在低版本中,plugin中的类由appclassloader加载,为了使用springboot的接口需要用springboot类加载器加载;
  2. 在高版本中,plugin中的类由pluginclassloader加载,pluginclassloader内部可以用线程类加载器加载到springboot的api; 高版本是否可以不用再声明factoryName为空的ClassInjectDefine?
Issues-translate-bot commented 3 months ago

Detect the issue's language is not English and translate it automatically.


Title: About the problem that factoryName in ClassInjectDefine is empty

What do you want to ask?

image

  1. In the lower version, the classes in the plugin are loaded by appclassloader. In order to use the springboot interface, you need to use the springboot classloader to load;
  2. In higher versions, the classes in the plugin are loaded by the pluginclassloader, and the thread classloader can be used inside the pluginclassloader to load to the springboot api; Is it possible to no longer declare ClassInjectDefine with empty factoryName in later versions?
hanbingleixue commented 2 months ago

@AYue-94 ClassInjectDefine is declared to ensure that these classes can be loaded through the class loader of the host. In later versions, ClassInjectDefine with empty factoryName also needs to be declared.

AYue-94 commented 2 months ago

I try to remove ClassInjectDefine with empty factoryName, for example in dynamic-config-plugin. image and the host springboot application can works well with dynamic-config-plugin.

for example:

  1. springboot LaunchedURLClassLoader load SpringEnvironmentProcessor but fail. fallback, Sermant ClassLoaderLoadClassInterceptor use PluginClassLoader load SpringEnvironmentProcessor, success;
  2. when SpringEnvironmentProcessor new DynamicConfigPropertySource will use PluginClassLoader too, its ok to find DynamicConfigPropertySource;
  3. DynamicConfigPropertySource implement springboot EnumerablePropertySource interface, EnumerablePropertySource is in LaunchedURLClassLoader, so PluginClassLoader fallback use thread context classloader load EnumerablePropertySource success;

so why need to declare DynamicConfigPropertySource in ClassInjectDefine with empty factoryName ? image

hanbingleixue commented 2 months ago

@AYue-94 These classes are loaded by the host to shield the original configuration center of the host. If these classes are not declared, the host can run properly, but the functions are affected.

AYue-94 commented 2 months ago

what does "functions are affected" mean? can you give me some example? I'm very confusion

hanbingleixue commented 2 months ago

@AYue-94 For example, the dynamic-config-plugin cannot shield the original configuration center after removing these declarations.

hanbingleixue commented 2 months ago

Answers have been provided, and no other questions are available. Therefore, this issue is closed.