1

I'm working with the developer of PF4J(Plugin Framework for Java) to provide better plugin functionality for Wicket. There is already a pf4j-spring and a pf4j-wicket project to provide some basic integration. In order to allow the @SpringBean or @Inject annotations to have access to plugin beans in a child context we need to be able to lookup the ApplicationContext associated with a specific class.

So for example, say I have a MyService bean in a child(plugin) ApplicationContext and that plugin also provides a panel that needs that via a @SpringBean annotation. Spring doesn't allow the parent ApplicationContext to see beans in a child context and for good reason. So we would get an exception saying that bean could not be found since @SpringBean only looks up beans in the parent context. We have code that we have developed that look up the child context like so:

SpringPlugin plugin = (SpringPlugin)PluginManager.whichPlugin(MyService.class);
ApplicationContext pluginContext = plugin.getApplicationContext();

How could I modify or provide this functionality in a custom version of SpringComponentInjector? It uses a ISpringContextLocator but that context locator does not specify the class for which it needs the ApplicationContext.

Any ideas on how this could be achieved?

Thanks for your help!

Wolfgang Fahl
  • 15,016
  • 11
  • 93
  • 186
Josh Chappelle
  • 1,558
  • 2
  • 15
  • 37

2 Answers2

0

I'm afraid current SpringComponentInjector is not prepared for such usage. You will have to create your own version.

The problem that I see is that you will have to have either as many IComponentInstantiationListeners as plugins there are. Or create a composite ICIL that delegates to SpringBeanLocators for each plugin. I think the composite would be better. Then you'll have to make sure that a Panel in pluginA cannot use a bean located by SpringBeanLocatorB.

If you manage to do it and you find something in wicket-spring that could be made more generic to help make your version simpler then please let us know and we will consider your suggestion(s)!

martin-g
  • 17,243
  • 2
  • 23
  • 35
  • Thanks martin-g. That's very similar to the approach that I have taken. I created an ICIL that would basically route requests based on the classloader of the Component. I did make my own custom version of the wicket-spring project and I modified ISpringContextLocator.getApplicationContext to take a Class parameter of the bean. Luckily, everywhere this was called, that was available. I'm still experimenting. I'll let you know if we get anywhere with it. Thanks for your answer. – Josh Chappelle Feb 25 '16 at 16:33
0

Take a look at sbp. It is built on top of pf4j to support Spring Boot, and also provides mechanism of sharing beans between main application and plugins. It looks like:

    @Override
    protected SpringBootstrap createSpringBootstrap() {
        return new SharedDataSourceSpringBootstrap(this, MdSimplePluginStarter.class)
            .addSharedBeanName("objectMapper")
            .addSharedBeanName("cacheService");
    }
Hank
  • 1,318
  • 10
  • 29