close

Filter

loading table of contents...

Blueprint Developer Manual / Version 2110

Table Of Contents
4.1.6.1.9 Plugin Dependencies

Plugins can also have dependencies on other plugins to make use of their classes and beans. Dependencies are declared in the property plugin.dependencies. You can declare just the dependent plugin's ID or a specific version or version range separated by @. Multiple dependencies can be declared separated by commas.

Examples

  • some-plugin

  • some-plugin@1.0.0

  • some-plugin@>=1.0.0 & <2.0.0

Providing Beans to Dependents

The configuration classes described in Section 4.1.6.1.5, “Application Beans in Plugins” are a kind of public beans API for your plugin. For each of those configuration classes, you need to create a class implementing the BeansForPluginsContainer marker Interface. This implementation serves as a container for your Beans and is injected into the dependents application context.

For every Bean definition in the Configuration class there should be a field, a constructor argument and a getter in the BeansForPluginsContainer class. The configuration class should have a field and a constructor with one argument of the concrete BeansForPluginsContainer type, so it can delegate to this field in its Bean defining methods. This way Spring can resolve the bean dependencies for the BeansForPluginsContainer classes and dependents of your plugin get a simple IDE supported way to find and inject your beans.

Example

PluginB depends on PluginA; PluginA provides a bean of type SomeBeanFromA to its dependencies and PluginB uses this bean.

PluginA
plugin.id=pluginA
plugin.version=1.2.3
plugin.configuration-class=com.acme.plugin_a.PluginAConfiguration

Example 4.8. PluginA plugin.properties


// Used to collect beans to be injected into dependent plugins
public class PluginABeansForPluginsContainer implements BeansForPluginsContainer {
  private final SomeBeanFromA someBeanFromA;

  public PluginABeansForPluginsContainer(SomeBeanFromA someBeanFromA) {
    this.someBeanFromA = someBeanFromA;
  }

  public SomeBeanFromA getSomeBeanFromA() {
    return someBeanFromA;
  }
}

Example 4.9. PluginABeansForPluginsContainer


// Defines a public API of Beans to be used by dependents
// and provides convenient access to beans from PluginABeansForPluginsContainer.
@BeansForPlugins
@Configuration(proxyBeanMethods = false)
public class PluginABeansForPlugins {
  private final PluginABeansForPluginsContainer pluginABeansForPluginsContainer;

  @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
  public PluginBeansAConfiguration(PluginABeansForPluginsContainer pluginABeansForPluginsContainer) {
    this.pluginABeansForPluginsContainer = pluginABeansForPluginsContainer;
  }

  @Bean
  public SomeBeanFromA someBeanFromA() {
    return pluginABeansForPluginsContainer.getSomeBeanFromA();
  }
}

Example 4.10. PluginABeansForPlugins


...
  @Bean
  SomeBeanFromA someBeanFromA() {
    return new SomeBeanFromA();
  }

  // Beans of type PluginBeans will be collected and injected into
  // dependents by the framework.
  @Bean
  PluginABeansForPluginsContainer pluginBeansA(SomeBeanFromA someBeanFromA) {
    return new PluginABeansForPluginsContainer(someBeanFromA);
  }
...

Example 4.11. PluginAConfiguration


PluginB
plugin.id=pluginB
plugin.version=0.1.0
plugin.configuration-class=com.acme.plugin_b.PluginBConfiguration
plugin.dependencies=pluginA

Example 4.12. PluginB plugin.properties


@Import(PluginABeansForPlugins.class)
@Configuration(proxyBeanMethods = false)
class PluginBConfiguration {
  ...
  @Bean
  SomeBeanForB someBeanForB(SomeBeanFromA someBeanFromA) {
    return new SomeBeanForB(someBeanFromA);
  }
  ...
}

Example 4.13. PluginBConfiguration


Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.