@Override public void configure(AtmosphereConfig config) { try { String s = config.getInitParameter(ATMOSPHERE_SPRING_EXCLUDE_CLASSES); if (s != null) { String[] list = s.split(","); for (String clazz : list) { excludedFromInjection.add(IOUtils.loadClass(getClass(), clazz)); } if (list.length > 0) { preventSpringInjection = true; } } context = new AnnotationConfigApplicationContext(); context.setParent( WebApplicationContextUtils.getWebApplicationContext( config.framework().getServletContext())); context.refresh(); // Hack to make it injectable context.register(AtmosphereConfig.class); ((AtmosphereConfig) context.getBean(AtmosphereConfig.class.getCanonicalName(), config.framework())) .populate(config); } catch (Exception ex) { logger.warn("Unable to configure injection", ex); } }
@Test public void testParentChildAnnotationConfigurationFromAnotherPackage() { AnnotationConfigApplicationContext child = new AnnotationConfigApplicationContext(); child.register(org.springframework.integration.configuration2.ChildConfiguration.class); child.setParent(this.context); child.refresh(); AbstractMessageChannel foo = child.getBean("foo", AbstractMessageChannel.class); ChannelInterceptor baz = child.getBean("baz", ChannelInterceptor.class); assertTrue(foo.getChannelInterceptors().contains(baz)); assertFalse(this.output.getChannelInterceptors().contains(baz)); child.close(); }
/** {@inheritDoc} */ public ApplicationContext getApplicationContext(ApplicationContext parent) { try { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.setParent(parent); for (String value : params.getValues()) { Class<?> clazz = ClassLoading.forName(value, AnnotationConfigApplicationContextProvider.class); ctx.register(clazz); } ctx.refresh(); return ctx; } catch (Exception e) { throw new RuntimeException("Could not create the ApplicationContext", e); } }