/** * Returns a Configurer instance with default components configured, such as a {@link SimpleCommandBus} and * {@link SimpleEventBus}, indicating whether to {@code autoLocateConfigurerModules}. * * When {@code autoLocateConfigurerModules} is {@code true}, a ServiceLoader will be used to locate all declared * instances of type {@link ConfigurerModule}. Each of the discovered instances will be invoked, allowing it to * set default values for the configuration. * * @param autoLocateConfigurerModules flag indicating whether ConfigurerModules on the classpath should be * automatically retrieved. Should be set to {@code false} when using an * application container, such as Spring or CDI. * @return Configurer instance for further configuration. */ public static Configurer defaultConfiguration(boolean autoLocateConfigurerModules) { DefaultConfigurer configurer = new DefaultConfigurer(); if(autoLocateConfigurerModules) { ServiceLoader<ConfigurerModule> configurerModuleLoader = ServiceLoader.load(ConfigurerModule.class, configurer.getClass().getClassLoader()); List<ConfigurerModule> configurerModules = new ArrayList<>(); configurerModuleLoader.forEach(configurerModules::add); configurerModules.sort(Comparator.comparingInt(ConfigurerModule::order)); configurerModules.forEach(cm -> cm.configureModule(configurer)); } return configurer; }
private void registerConfigurerModules(Configurer configurer) { String[] configurerModules = beanFactory.getBeanNamesForType(ConfigurerModule.class); for (String configurerModuleBeanName : configurerModules) { ConfigurerModule configurerModule = beanFactory.getBean(configurerModuleBeanName, ConfigurerModule.class); configurerModule.configureModule(configurer); } }
/** * Returns a Configurer instance with default components configured, such as a {@link SimpleCommandBus} and * {@link SimpleEventBus}, indicating whether to {@code autoLocateConfigurerModules}. * * When {@code autoLocateConfigurerModules} is {@code true}, a ServiceLoader will be used to locate all declared * instances of type {@link ConfigurerModule}. Each of the discovered instances will be invoked, allowing it to * set default values for the configuration. * * @param autoLocateConfigurerModules flag indicating whether ConfigurerModules on the classpath should be * automatically retrieved. Should be set to {@code false} when using an * application container, such as Spring or CDI. * @return Configurer instance for further configuration. */ public static Configurer defaultConfiguration(boolean autoLocateConfigurerModules) { DefaultConfigurer configurer = new DefaultConfigurer(); if(autoLocateConfigurerModules) { ServiceLoader<ConfigurerModule> configurerModuleLoader = ServiceLoader.load(ConfigurerModule.class, configurer.getClass().getClassLoader()); List<ConfigurerModule> configurerModules = new ArrayList<>(); configurerModuleLoader.forEach(configurerModules::add); configurerModules.sort(Comparator.comparingInt(ConfigurerModule::order)); configurerModules.forEach(cm -> cm.configureModule(configurer)); } return configurer; }