Hi author:
In my cases,many plugins need to use services provided by the host application,so I had the idea of supporting a Spring parent-child context
Example Code:
`
Desc: Then SpringPlugin#getApplicaitonContext and SpringPlugin#createApplicationContext methods can take Parent-ApplicaitonContext as a input parameter.
public abstract class SpringPlugin extends Plugin {
`
SingletonSpringExtensionFactory
Desc: I think this class is For Spring,so you don't have to use the PluginManager , we can replace SpringPluginManager with PluginManager
public class SingletonSpringExtensionFactory extends SpringExtensionFactory {
private final List<String> extensionClassNames;
private Map<String, Object> cache;
public SingletonSpringExtensionFactory(**SpringPluginManager pluginManager**) {
this(pluginManager, true);
}
public SingletonSpringExtensionFactory(**SpringPluginManager pluginManager**, String... extensionClassNames) {
this(pluginManager, true, extensionClassNames);
}
public SingletonSpringExtensionFactory(**SpringPluginManager pluginManager**, boolean autowire, String... extensionClassNames) {
super(pluginManager, autowire);
this.extensionClassNames = Arrays.asList(extensionClassNames);
cache = new HashMap<>(); // simple cache implementation
}
@Override
@SuppressWarnings("unchecked")
public <T> T create(Class<T> extensionClass) {
String extensionClassName = extensionClass.getName();
if (cache.containsKey(extensionClassName)) {
return (T) cache.get(extensionClassName);
}
T extension = super.create(extensionClass);
if (extensionClassNames.isEmpty() || extensionClassNames.contains(extensionClassName)) {
cache.put(extensionClassName, extension);
}
return extension;
}
}
`
`
SpringExtensionFactory
Desc: I think this class is For Spring,so you don't have to use the PluginManager , we can replace SpringPluginManager with PluginManager
/**
The plugin manager is used for retrieving a plugin from a given extension class
and as a fallback supplier of an application context.
*/
protected final SpringPluginManager pluginManager;
/**
Indicates if springs autowiring possibilities should be used.
*/
protected final boolean autowire;
public SpringExtensionFactory(final SpringPluginManager pluginManager) {
this(pluginManager, AUTOWIRE_BY_DEFAULT);
}
public SpringExtensionFactory(final SpringPluginManager pluginManager, final boolean autowire) {
this.pluginManager = pluginManager;
this.autowire = autowire;
if (!autowire) {
log.warn("Autowiring is disabled although the only reason for existence of this special factory is" +
" supporting spring and its application context.");
}
}
`
Hi author: In my cases,many plugins need to use services provided by the host application,so I had the idea of supporting a Spring parent-child context
Example Code: ` Desc: Then SpringPlugin#getApplicaitonContext and SpringPlugin#createApplicationContext methods can take Parent-ApplicaitonContext as a input parameter.
public abstract class SpringPlugin extends Plugin {
} `
` SingletonSpringExtensionFactory Desc: I think this class is For Spring,so you don't have to use the PluginManager , we can replace SpringPluginManager with PluginManager
public class SingletonSpringExtensionFactory extends SpringExtensionFactory {
} `
` SpringExtensionFactory Desc: I think this class is For Spring,so you don't have to use the PluginManager , we can replace SpringPluginManager with PluginManager /**
Indicates if springs autowiring possibilities should be used. */ protected final boolean autowire;
public SpringExtensionFactory(final SpringPluginManager pluginManager) { this(pluginManager, AUTOWIRE_BY_DEFAULT); }
public SpringExtensionFactory(final SpringPluginManager pluginManager, final boolean autowire) { this.pluginManager = pluginManager; this.autowire = autowire; if (!autowire) { log.warn("Autowiring is disabled although the only reason for existence of this special factory is" + " supporting spring and its application context."); } } `
The pull request link :https://github.com/pf4j/pf4j-spring/pull/68