Example usage for org.springframework.web.context WebApplicationContext publishEvent

List of usage examples for org.springframework.web.context WebApplicationContext publishEvent

Introduction

In this page you can find the example usage for org.springframework.web.context WebApplicationContext publishEvent.

Prototype

default void publishEvent(ApplicationEvent event) 

Source Link

Document

Notify all matching listeners registered with this application of an application event.

Usage

From source file:org.codehaus.groovy.grails.commons.spring.GrailsRuntimeConfigurator.java

public WebApplicationContext configure(ServletContext context, boolean loadExternalBeans) {
    Assert.notNull(application);//from www .  j  a v  a  2s  . c o m

    // TODO GRAILS-720 this causes plugin beans to be re-created - should get getApplicationContext always call refresh?
    WebApplicationContext ctx;
    try {
        webSpringConfig = createWebRuntimeSpringConfiguration(application, parent,
                application.getClassLoader());
        webSpringConfig.setBeanFactory(new ReloadAwareAutowireCapableBeanFactory());

        if (context != null) {
            webSpringConfig.setServletContext(context);
            pluginManager.setServletContext(context);
        }
        if (!pluginManager.isInitialised()) {
            pluginManager.loadPlugins();
        }

        if (!application.isInitialised()) {
            pluginManager.doArtefactConfiguration();
            application.initialise();
        }

        pluginManager.registerProvidedArtefacts(application);

        registerParentBeanFactoryPostProcessors(webSpringConfig);

        pluginManager.doRuntimeConfiguration(webSpringConfig);

        LOG.debug("[RuntimeConfiguration] Processing additional external configurations");

        if (loadExternalBeans) {
            doPostResourceConfiguration(application, webSpringConfig);
        }

        reset();

        application.setMainContext(webSpringConfig.getUnrefreshedApplicationContext());

        Environment.setInitializing(true);
        ctx = (WebApplicationContext) webSpringConfig.getApplicationContext();
        Environment.setInitializing(false);

        pluginManager.setApplicationContext(ctx);
        pluginManager.doDynamicMethods();

        ctx.publishEvent(new GrailsContextEvent(ctx, GrailsContextEvent.DYNAMIC_METHODS_REGISTERED));

        performPostProcessing(ctx);

        application.refreshConstraints();
    } finally {
        ClassPropertyFetcher.clearClassPropertyFetcherCache();
    }

    return ctx;
}

From source file:org.grails.web.servlet.context.support.GrailsRuntimeConfigurator.java

public WebApplicationContext configure(ServletContext context, boolean loadExternalBeans) {
    Assert.notNull(application);/*w  w  w  .j a v  a 2s  .c  o  m*/

    // TODO GRAILS-720 this causes plugin beans to be re-created - should get getApplicationContext always call refresh?
    WebApplicationContext mainContext;
    try {
        webSpringConfig = createWebRuntimeSpringConfiguration(application, parent,
                application.getClassLoader());

        if (context != null) {
            webSpringConfig.setServletContext(context);
        }
        if (!pluginManager.isInitialised()) {
            pluginManager.loadPlugins();
        }

        if (!application.isInitialised()) {
            pluginManager.doArtefactConfiguration();
            application.initialise();
        }

        pluginManager.registerProvidedArtefacts(application);
        pluginManager.doRuntimeConfiguration(webSpringConfig);

        LOG.debug("[RuntimeConfiguration] Processing additional external configurations");

        if (loadExternalBeans) {
            doPostResourceConfiguration(application, webSpringConfig);
        }

        reset();

        mainContext = (WebApplicationContext) webSpringConfig.getUnrefreshedApplicationContext();
        application.setMainContext(mainContext);

        Environment.setInitializing(true);
        initializeContext(mainContext);
        Environment.setInitializing(false);

        pluginManager.setApplicationContext(mainContext);
        pluginManager.doDynamicMethods();

        mainContext.publishEvent(
                new GrailsContextEvent(mainContext, GrailsContextEvent.DYNAMIC_METHODS_REGISTERED));

        performPostProcessing(mainContext);

        application.refreshConstraints();
    } finally {
        ClassPropertyFetcher.clearClassPropertyFetcherCache();
    }

    return mainContext;
}

From source file:org.jahia.bin.listeners.JahiaContextLoaderListener.java

@Override
public void contextInitialized(ServletContextEvent event) {

    startupTime = System.currentTimeMillis();
    startupWithTrust(Jahia.isEnterpriseEdition() ? (Jahia.getBuildNumber() + "." + Jahia.getEEBuildNumber())
            : String.valueOf(Jahia.getBuildNumber()));

    logger.info("Starting up Digital Experience Manager, please wait...");

    servletContext = event.getServletContext();

    Jahia.setContextPath(servletContext.getContextPath());

    initWebAppRoot();//from ww w. j  a  va  2  s. c  om

    if (System.getProperty("jahia.config") == null) {
        setSystemProperty("jahia.config", "");
    }
    if (System.getProperty("jahia.license") == null) {
        setSystemProperty("jahia.license", "");
    }

    try {
        // verify supported Java version
        Jahia.verifyJavaVersion(servletContext.getInitParameter("supported_jdk_versions"));
    } catch (JahiaInitializationException e) {
        throw new JahiaRuntimeException(e);
    }

    detectPID(servletContext);

    GroovyPatcher.executeScripts(servletContext, "beforeContextInitializing");

    // initialize VFS file system (solves classloader issue: https://issues.apache.org/jira/browse/VFS-228 )
    try {
        VFS.getManager();
    } catch (FileSystemException e) {
        throw new JahiaRuntimeException(e);
    }

    try {
        long timer = System.currentTimeMillis();
        logger.info("Start initializing Spring root application context");

        running = true;

        super.contextInitialized(event);

        logger.info("Spring Root application context initialized in {} ms",
                (System.currentTimeMillis() - timer));

        // initialize services registry
        ServicesRegistry.getInstance().init();

        // fire Spring event that the root context is initialized
        WebApplicationContext rootCtx = ContextLoader.getCurrentWebApplicationContext();
        rootCtx.publishEvent(new RootContextInitializedEvent(rootCtx));

        if (Jahia.isEnterpriseEdition()) {
            requireLicense();
        }

        boolean isProcessingServer = SettingsBean.getInstance().isProcessingServer();

        // execute patches after root context initialization
        if (isProcessingServer) {
            GroovyPatcher.executeScripts(servletContext, "rootContextInitialized");
        }

        // start OSGi container
        FrameworkService.getInstance().start();

    } catch (JahiaException e) {
        running = false;
        logger.error(e.getMessage(), e);
        throw new JahiaRuntimeException(e);
    } catch (RuntimeException e) {
        running = false;
        throw e;
    } finally {
        JCRSessionFactory.getInstance().closeAllSessions();
    }
}