pf4j / pf4j-spring

Plugin Framework for Spring (PF4J - Spring Framework integration)
Apache License 2.0
332 stars 104 forks source link

How to update the ‘List<Greeting>’ while some plugins unloaded and deleted? #62

Open jeven2016 opened 3 years ago

jeven2016 commented 3 years ago

Hi,

Could you take a look at this questions?

Question: How to update the ‘List’ bean while some plugins are unloaded/deleted?

public class Greetings {

  @Autowired
  private List<Greeting> greetings;

  public void printGreetings() {
    System.out.println(String
        .format("Found %d extensions for extension point '%s'", greetings.size(),
            Greeting.class.getName()));
    for (Greeting greeting : greetings) {
      System.out.println(">>> " + greeting.greeting());
    }
  }

}
  1. At the begining, there're 3 extensions found

    Found 3 extensions for extension point 'api.Greeting'
    >>> custom
    >>> Plugin2Greeting
    >>> Plugin1Greeting
  2. And I'd like to unload plugin-1 and try to replace it with a new plugin latter

    
    @GetMapping("uninstall/{pluginId}")
    public Flux<String> uninstall(@PathVariable String pluginId) {
    pluginManager.stopPlugin(pluginId);
    pluginManager.unloadPlugin(pluginId);
    return Flux.just("ok");
    }

3. unfortunately, there're still be 3 extensions printed after the plugin-1 is unloaded.....

So how to update the bean 'List<Greeting>' during runtime, or any samples illustrate how to integrate with pf4j-update?

Thanks.
HuangDayu commented 3 years ago

@jeven2016 你好,我也正苦恼这个问题,插件卸载之后,其注入的bean依然可用,除了自主管理bean,还有什么其他更好的办法吗?多个pf4j的衍生版本都存在这个问题。

@JEVEN2016 Hello, I am also worried about this problem. After the plugin is uninstalled, the bean that is injected is still available. In addition to independent management bean, what other better ways? This problem exists in a derived version of multiple PF4J.

decebals commented 3 years ago

unfortunately, there're still be 3 extensions printed after the plugin-1 is unloaded.....

I am afraid that here it's necessary a context reload or something similar.

or any samples illustrate how to integrate with pf4j-update?

you can take a look on the readme page of project (https://github.com/pf4j/pf4j-update) or in UpdateIntegrationTest.

jeven2016 commented 3 years ago

@HuangDayu 只有重启才行,我尝试了其他的插件系统,目前还没有这类的多版本运行时升级不重启生效的。

neasonpy commented 2 years ago

@HuangDayu 只有重启才行,我尝试了其他的插件系统,目前还没有这类的多版本运行时升级不重启生效的。

try SOFA Ark or SOFA Jarlinks to switch multi-version plugin.