Let say we have a Spring bean:
@Component
class PluginsProviderImpl implements PluginsProvider {
private final List<PluginInterface> plugins;
public PluginsProviderImpl(List<PluginInterface> plugins){
this.plugins = plugins;
}
//...
}
The implementations of PluginInterface have runtime dependency with the core system and are provided externally. It is possible that sometimes, some of them are erroneous (e.g. their dependencies are missing). If there is a such an error while Spring context initialization - the whole application does not start (even thou the broken plugin is not required to its proper operation).
Is it possible to control Spring context loading in such a way that, if error occurs in one of the PluginInterface implementations, skip it and proceed with initialization?
UPDATE: More explanation: I Do not need to add a bean conditionally. I want to skip a bean that is erroneous and the problem appears during context initialization. This is a plugin - provided at runtime.
Even more explanation: I want to application start even if one of the plugin introduced implementations of PluginInterface cannot be initialized.