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

Fix ModuleProvider is repeated loading (#2923)

上级 980c019f
......@@ -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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册