SpringExtensionFactory implements ExtensionFactory { @Override @SuppressWarnings("unchecked") public <T> T getExtension(Class<T> type, String name) { if (type.isInterface() && type.isAnnotationPresent(SPI.class)) { return null; } for (ApplicationContext context : CONTEXTS) { T bean = BeanFactoryUtils.getOptionalBean(context, name, type); if (bean != null) { return bean; } } return null; }  static void addApplicationContext(ApplicationContext context); static void removeApplicationContext(ApplicationContext context); static Set<ApplicationContext> getContexts(); static void clearContexts(); @Override @SuppressWarnings("unchecked") T getExtension(Class<T> type, String name);  }
@Test public void testGetExtensionBySPI() { Protocol protocol = springExtensionFactory.getExtension(Protocol.class, "protocol"); Assertions.assertNull(protocol); }
@Test public void testGetExtensionByName() { DemoService bean = springExtensionFactory.getExtension(DemoService.class, "bean1"); Assertions.assertNotNull(bean); HelloService hello = springExtensionFactory.getExtension(HelloService.class, "hello"); Assertions.assertNotNull(hello); }