ZipkinModuleImporter implements ApplicationContextInitializer<GenericApplicationContext> { @Override public void initialize(GenericApplicationContext context) { ConfigurableEnvironment env = context.getEnvironment(); Map<String, String> modules = Binder.get(env).bind(PROPERTY_NAME_MODULE, Map.class).orElse(null); if (modules == null || modules.isEmpty()) { LOG.debug("no modules found under path " + PROPERTY_NAME_MODULE); return; } LOG.debug("attempting to load modules: " + modules.keySet()); for (Map.Entry<String, String> module : modules.entrySet()) { try { context.registerBean(Class.forName(module.getValue())); } catch (Exception e) { LOG.debug("skipping unloadable module " + module.getKey(), e); } } }  @Override void initialize(GenericApplicationContext context);  }
@Test public void doesntCrashWhenNoModules() { zipkinModuleImporter.initialize(context); context.refresh(); }
@Test public void configuresModule() { TestPropertyValues.of( "zipkin.internal.module.module1=" + Module1.class.getName() ).applyTo(context); zipkinModuleImporter.initialize(context); context.refresh(); context.getBean(Module1.class); }
@Test public void doesntCrashWhenBadModule() { TestPropertyValues.of( "zipkin.internal.module.module1=tomatoes" ).applyTo(context); zipkinModuleImporter.initialize(context); context.refresh(); }
@Test public void configuresModules() { TestPropertyValues.of( "zipkin.internal.module.module1=" + Module1.class.getName(), "zipkin.internal.module.module2=" + Module2.class.getName() ).applyTo(context); zipkinModuleImporter.initialize(context); context.refresh(); context.getBean(Module1.class); context.getBean(Module2.class); }