Search in sources :

Example 81 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project engine by craftercms.

the class SiteContextFactory method createContext.

public SiteContext createContext(String siteName) {
    Map<String, String> macroValues = Collections.singletonMap(siteNameMacroName, siteName);
    String resolvedRootFolderPath = macroResolver.resolveMacros(rootFolderPath, macroValues);
    Context context = storeService.createContext(storeType, storeServerUrl, username, password, resolvedRootFolderPath, mergingOn, cacheOn, maxAllowedItemsInCache, ignoreHiddenFiles);
    try {
        SiteContext siteContext = new SiteContext();
        siteContext.setStoreService(storeService);
        siteContext.setSiteName(siteName);
        siteContext.setContext(context);
        siteContext.setStaticAssetsPath(staticAssetsPath);
        siteContext.setTemplatesPath(templatesPath);
        siteContext.setFreeMarkerConfig(freeMarkerConfigFactory.getObject());
        siteContext.setUrlTransformationEngine(urlTransformationEngine);
        siteContext.setOverlayCallback(overlayCallback);
        siteContext.setRestScriptsPath(restScriptsPath);
        siteContext.setControllerScriptsPath(controllerScriptsPath);
        String[] resolvedConfigPaths = new String[configPaths.length];
        for (int i = 0; i < configPaths.length; i++) {
            resolvedConfigPaths[i] = macroResolver.resolveMacros(configPaths[i], macroValues);
        }
        String[] resolvedAppContextPaths = new String[applicationContextPaths.length];
        for (int i = 0; i < applicationContextPaths.length; i++) {
            resolvedAppContextPaths[i] = macroResolver.resolveMacros(applicationContextPaths[i], macroValues);
        }
        ResourceLoader resourceLoader = new ContentStoreResourceLoader(siteContext);
        HierarchicalConfiguration<?> config = getConfig(siteContext, resolvedConfigPaths, resourceLoader);
        URLClassLoader classLoader = getClassLoader(siteContext);
        ScriptFactory scriptFactory = getScriptFactory(siteContext, classLoader);
        ConfigurableApplicationContext appContext = getApplicationContext(siteContext, classLoader, config, resolvedAppContextPaths, resourceLoader);
        siteContext.setConfigPaths(resolvedConfigPaths);
        siteContext.setApplicationContextPaths(resolvedAppContextPaths);
        siteContext.setGroovyClassesPath(groovyClassesPath);
        siteContext.setScriptFactory(scriptFactory);
        siteContext.setConfig(config);
        siteContext.setGlobalApplicationContext(globalApplicationContext);
        siteContext.setApplicationContext(appContext);
        siteContext.setClassLoader(classLoader);
        executeInitScript(siteContext, scriptFactory);
        Scheduler scheduler = scheduleJobs(siteContext);
        siteContext.setScheduler(scheduler);
        return siteContext;
    } catch (Exception e) {
        // Destroy context if the site context creation failed
        storeService.destroyContext(context);
        throw e;
    }
}
Also used : JobContext(org.craftercms.engine.util.quartz.JobContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) Context(org.craftercms.core.service.Context) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) ServletContext(javax.servlet.ServletContext) ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ContentStoreGroovyResourceLoader(org.craftercms.engine.util.groovy.ContentStoreGroovyResourceLoader) ResourceLoader(org.springframework.core.io.ResourceLoader) ContentStoreResourceLoader(org.craftercms.engine.util.spring.ContentStoreResourceLoader) Scheduler(org.quartz.Scheduler) ContentStoreResourceLoader(org.craftercms.engine.util.spring.ContentStoreResourceLoader) SiteContextCreationException(org.craftercms.engine.exception.SiteContextCreationException) BeansException(org.springframework.beans.BeansException) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) URLClassLoader(java.net.URLClassLoader) GroovyScriptFactory(org.craftercms.engine.scripting.impl.GroovyScriptFactory) ScriptFactory(org.craftercms.engine.scripting.ScriptFactory)

Example 82 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project uPortal by Jasig.

the class PortalApplicationContextLocator method shutdown.

/**
 * If the ApplicationContext returned by {@link #getApplicationContext()} is 'portal managed'
 * the shutdown hook for the context is called, closing and cleaning up all spring managed
 * resources.
 *
 * <p>If the ApplicationContext returned by {@link #getApplicationContext()} is actually a
 * WebApplicationContext this method does nothing but log an error message.
 */
public static void shutdown() {
    if (applicationContextCreator.isCreated()) {
        final ConfigurableApplicationContext applicationContext = applicationContextCreator.get();
        applicationContext.close();
    } else {
        final IllegalStateException createException = new IllegalStateException("No portal managed ApplicationContext has been created, there is nothing to shutdown.");
        getLogger().error(createException, createException);
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext)

Example 83 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project java-function-invoker by projectriff.

the class BeanCountingApplicationListener method onApplicationEvent.

@SuppressWarnings("resource")
@Override
public void onApplicationEvent(ApplicationReadyEvent event) {
    if (!event.getApplicationContext().equals(this.context)) {
        return;
    }
    int count = 0;
    ConfigurableApplicationContext context = event.getApplicationContext();
    String id = context.getId();
    List<String> names = new ArrayList<>();
    while (context != null) {
        count += context.getBeanDefinitionCount();
        names.addAll(Arrays.asList(context.getBeanDefinitionNames()));
        context = (ConfigurableApplicationContext) context.getParent();
    }
    logger.info("Bean count: " + id + "=" + count);
    logger.debug("Bean names: " + id + "=" + names);
    try {
        logger.info("Class count: " + id + "=" + ManagementFactory.getClassLoadingMXBean().getTotalLoadedClassCount());
    } catch (Exception e) {
    }
    if (isSpringBootApplication(sources(event))) {
        try {
            logger.info(MARKER);
        } catch (Exception e) {
        }
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ArrayList(java.util.ArrayList) BeansException(org.springframework.beans.BeansException)

Example 84 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project nikita-noark5-core by HiOA-ABI.

the class N5CoreApp method main.

/**
     * Main method, used to run the application.
     *
     * @param args the command line arguments
     * @throws UnknownHostException if the local host name could not be resolved into an address
     */
public static void main(final String... args) throws UnknownHostException {
    //SpringApplication app = new SpringApplication(N5CoreApp.class);
    //SimpleCommandLinePropertySource source = new SimpleCommandLinePropertySource(args);
    ConfigurableApplicationContext context = SpringApplication.run(CONFIGS, args);
    context.getBean(AfterApplicationStartup.class).afterApplicationStarts();
    Environment env = context.getEnvironment();
    String[] activeProfiles = env.getActiveProfiles();
    String profilesAsString = Arrays.toString(activeProfiles);
    logger.info("\n----------------------------------------------------------\n\t" + "Application '{}' is running! Access URLs:\n\t" + "Local: \t\t\thttp://localhost:{}\n\t" + "External: \t\thttp://{}:{}\n\t" + "contextPath: \thttp://{}:{}{} \n\t" + "Application is running with following profile(s): {} \n\t" + "\n----------------------------------------------------------", env.getProperty("spring.application.name"), env.getProperty("server.port"), InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), env.getProperty("server.contextPath"), profilesAsString);
    String configServerStatus = env.getProperty("configserver.status");
    logger.info("\n----------------------------------------------------------\n\t" + "Config Server: \t{}\n----------------------------------------------------------", configServerStatus == null ? "Not found or not setup for this application" : configServerStatus);
    if (profilesAsString != null && profilesAsString.contains("de")) {
        logger.info("\n----------------------------------------------------------\n\t" + "Dev/demo mode: In-memory database ({}) in use. See http://localhost:8082 . Use following JDBC-string: jdbc:h2:mem:n5DemoDb/jdbc:h2:mem:n5DevDb" + "\n----------------------------------------------------------", env.getProperty("spring.jpa.database"));
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) Environment(org.springframework.core.env.Environment)

Example 85 with ConfigurableApplicationContext

use of org.springframework.context.ConfigurableApplicationContext in project dubbo by alibaba.

the class Spring3CompatibilityTest method startupProvider.

private static ConfigurableApplicationContext startupProvider() {
    ConfigurableApplicationContext context = startupApplicationContext(ProviderConfiguration.class);
    System.out.println("Startup Provider ...");
    return context;
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext)

Aggregations

ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)177 Test (org.junit.Test)110 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)42 SpringApplicationBuilder (org.springframework.boot.builder.SpringApplicationBuilder)17 ApplicationContext (org.springframework.context.ApplicationContext)17 SpringApplication (org.springframework.boot.SpringApplication)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)13 DataSource (javax.sql.DataSource)8 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)7 JmsListenerContainerTestFactory (org.springframework.jms.config.JmsListenerContainerTestFactory)7 MBeanServer (javax.management.MBeanServer)6 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)6 Statement (java.sql.Statement)5 ArrayList (java.util.ArrayList)5 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)5 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)5 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)5 GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)5 ObjectName (javax.management.ObjectName)4