@Override protected void customizeContext(GenericApplicationContext context) { assertFalse("The context should not yet have been refreshed.", context.isActive()); builder.append(expectedContents); } }.loadContext("classpath:/org/springframework/test/context/support/CustomizedGenericXmlContextLoaderTests-context.xml");
public boolean isAlive() { return applicationContext.isActive(); }
private GenericApplicationContext getContext() { if (!context.isActive()) { context.refresh(); } return context; }
private GenericApplicationContext getContext() { if (!context.isActive()) context.refresh(); return context; }
@Override public <T> T getComponent(Class<T> requiredType) { return (this.context.isActive()) ? this.context.getBean(requiredType) : null; }
@Override public <T> T getComponent(String componentName, Class<T> requiredType) { if (this.context.isActive() && this.context.containsBean(componentName)) { return context.getBean(componentName, requiredType); } return null; }
public static void boot() { LOGGER.log(INFO, "Booting modular spring application"); synchronized (moduleContexts) { for (Map.Entry<Module, GenericApplicationContext> contextEntry : moduleContexts.entrySet()) { Module module = contextEntry.getKey(); GenericApplicationContext context = contextEntry.getValue(); if (!context.isActive()) { LOGGER.log(INFO, "Starting ApplicationContext for Module " + module.getName()); context.refresh(); } else { LOGGER.log(INFO, "ApplicationContext for Module " + module.getName() + " is already active"); } } } }
@Override public void shutdown() { if (context.isActive()) if (canFind(StickySystemStartup.class)) find(StickySystemStartup.class).shutdown(); context.close(); }
/** * Initializes the Spring {@link GenericApplicationContext} and returns all instances of {@link SpringCamelContext} beans. * * Note that {@link SpringCamelContext} instances are created in the <b>stopped</b> state. Starting the {@link SpringCamelContext} * is left to the caller. * * @return Unmodifiable list of {@link SpringCamelContext} instances * @throws Exception */ public List<SpringCamelContext> createSpringCamelContexts() throws Exception { if (applicationContext.isActive()) { throw new IllegalStateException("Unable to refresh Spring application context. Context is already initialized"); } SpringCamelContext.setNoStart(true); ProxyUtils.invokeProxied(new ProxiedAction() { @Override public void run() throws Exception { applicationContext.refresh(); } }, applicationContext.getClassLoader()); SpringCamelContext.setNoStart(false); return getSpringCamelContexts(); }
/** * Initializes the Spring {@link GenericApplicationContext} and returns all instances of {@link SpringCamelContext} beans. * * Note that {@link SpringCamelContext} instances are created in the <b>stopped</b> state. Starting the {@link SpringCamelContext} * is left to the caller. * * @return Unmodifiable list of {@link SpringCamelContext} instances * @throws Exception */ public List<SpringCamelContext> createSpringCamelContexts() throws Exception { if (applicationContext.isActive()) { throw new IllegalStateException("Unable to refresh Spring application context. Context is already initialized"); } SpringCamelContext.setNoStart(true); ProxyUtils.invokeProxied(new ProxiedAction() { @Override public void run() throws Exception { applicationContext.refresh(); } }, applicationContext.getClassLoader()); SpringCamelContext.setNoStart(false); return getSpringCamelContexts(); }
public static <SERVICETYPE> SERVICETYPE retrieveInstanceFromContext(Class<SERVICETYPE> serviceClass) { LOGGER.log(INFO, "Providing instance of " + serviceClass.getSimpleName() + " from module " + serviceClass.getModule().getName()); GenericApplicationContext context = get(); if (!context.isActive()) { LOGGER.log(INFO, "Lazy starting ApplicationContext for module " + serviceClass.getModule().getName()); context.refresh(); } return context.getBean(serviceClass); }