Fix ModuleProvider is repeated loading (#2923)
This commit is contained in:
parent
980c019f11
commit
fa7a1983f9
|
|
@ -58,9 +58,8 @@ public abstract class ModuleDefine implements ModuleProviderHolder {
|
|||
* @param configuration of this module
|
||||
* @throws ProviderNotFoundException when even don't find a single one providers.
|
||||
*/
|
||||
void prepare(ModuleManager moduleManager,
|
||||
ApplicationConfiguration.ModuleConfiguration configuration) throws ProviderNotFoundException, ServiceNotProvidedException, ModuleConfigException, ModuleStartException {
|
||||
ServiceLoader<ModuleProvider> moduleProviderLoader = ServiceLoader.load(ModuleProvider.class);
|
||||
void prepare(ModuleManager moduleManager, ApplicationConfiguration.ModuleConfiguration configuration,
|
||||
ServiceLoader<ModuleProvider> moduleProviderLoader) throws ProviderNotFoundException, ServiceNotProvidedException, ModuleConfigException, ModuleStartException {
|
||||
boolean providerExist = false;
|
||||
for (ModuleProvider provider : moduleProviderLoader) {
|
||||
if (!configuration.has(provider.name())) {
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@ public class ModuleManager implements ModuleDefineHolder {
|
|||
ApplicationConfiguration applicationConfiguration) throws ModuleNotFoundException, ProviderNotFoundException, ServiceNotProvidedException, CycleDependencyException, ModuleConfigException, ModuleStartException {
|
||||
String[] moduleNames = applicationConfiguration.moduleList();
|
||||
ServiceLoader<ModuleDefine> moduleServiceLoader = ServiceLoader.load(ModuleDefine.class);
|
||||
ServiceLoader<ModuleProvider> moduleProviderLoader = ServiceLoader.load(ModuleProvider.class);
|
||||
|
||||
LinkedList<String> moduleList = new LinkedList<>(Arrays.asList(moduleNames));
|
||||
for (ModuleDefine module : moduleServiceLoader) {
|
||||
for (String moduleName : moduleNames) {
|
||||
|
|
@ -47,7 +49,7 @@ public class ModuleManager implements ModuleDefineHolder {
|
|||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
throw new ModuleNotFoundException(e);
|
||||
}
|
||||
newInstance.prepare(this, applicationConfiguration.getModuleConfiguration(moduleName));
|
||||
newInstance.prepare(this, applicationConfiguration.getModuleConfiguration(moduleName), moduleProviderLoader);
|
||||
loadedModules.put(moduleName, newInstance);
|
||||
moduleList.remove(moduleName);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue