提交 fa7a1983 编写于 作者: D daming 提交者: wu-sheng

Fix ModuleProvider is repeated loading (#2923)

上级 980c019f
...@@ -58,9 +58,8 @@ public abstract class ModuleDefine implements ModuleProviderHolder { ...@@ -58,9 +58,8 @@ public abstract class ModuleDefine implements ModuleProviderHolder {
* @param configuration of this module * @param configuration of this module
* @throws ProviderNotFoundException when even don't find a single one providers. * @throws ProviderNotFoundException when even don't find a single one providers.
*/ */
void prepare(ModuleManager moduleManager, void prepare(ModuleManager moduleManager, ApplicationConfiguration.ModuleConfiguration configuration,
ApplicationConfiguration.ModuleConfiguration configuration) throws ProviderNotFoundException, ServiceNotProvidedException, ModuleConfigException, ModuleStartException { ServiceLoader<ModuleProvider> moduleProviderLoader) throws ProviderNotFoundException, ServiceNotProvidedException, ModuleConfigException, ModuleStartException {
ServiceLoader<ModuleProvider> moduleProviderLoader = ServiceLoader.load(ModuleProvider.class);
boolean providerExist = false; boolean providerExist = false;
for (ModuleProvider provider : moduleProviderLoader) { for (ModuleProvider provider : moduleProviderLoader) {
if (!configuration.has(provider.name())) { if (!configuration.has(provider.name())) {
......
...@@ -37,6 +37,8 @@ public class ModuleManager implements ModuleDefineHolder { ...@@ -37,6 +37,8 @@ public class ModuleManager implements ModuleDefineHolder {
ApplicationConfiguration applicationConfiguration) throws ModuleNotFoundException, ProviderNotFoundException, ServiceNotProvidedException, CycleDependencyException, ModuleConfigException, ModuleStartException { ApplicationConfiguration applicationConfiguration) throws ModuleNotFoundException, ProviderNotFoundException, ServiceNotProvidedException, CycleDependencyException, ModuleConfigException, ModuleStartException {
String[] moduleNames = applicationConfiguration.moduleList(); String[] moduleNames = applicationConfiguration.moduleList();
ServiceLoader<ModuleDefine> moduleServiceLoader = ServiceLoader.load(ModuleDefine.class); ServiceLoader<ModuleDefine> moduleServiceLoader = ServiceLoader.load(ModuleDefine.class);
ServiceLoader<ModuleProvider> moduleProviderLoader = ServiceLoader.load(ModuleProvider.class);
LinkedList<String> moduleList = new LinkedList<>(Arrays.asList(moduleNames)); LinkedList<String> moduleList = new LinkedList<>(Arrays.asList(moduleNames));
for (ModuleDefine module : moduleServiceLoader) { for (ModuleDefine module : moduleServiceLoader) {
for (String moduleName : moduleNames) { for (String moduleName : moduleNames) {
...@@ -47,7 +49,7 @@ public class ModuleManager implements ModuleDefineHolder { ...@@ -47,7 +49,7 @@ public class ModuleManager implements ModuleDefineHolder {
} catch (InstantiationException | IllegalAccessException e) { } catch (InstantiationException | IllegalAccessException e) {
throw new ModuleNotFoundException(e); throw new ModuleNotFoundException(e);
} }
newInstance.prepare(this, applicationConfiguration.getModuleConfiguration(moduleName)); newInstance.prepare(this, applicationConfiguration.getModuleConfiguration(moduleName), moduleProviderLoader);
loadedModules.put(moduleName, newInstance); loadedModules.put(moduleName, newInstance);
moduleList.remove(moduleName); moduleList.remove(moduleName);
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册