Search in sources :

Example 1 with ApplicationContextCustomizer

use of org.apache.tapestry5.spring.ApplicationContextCustomizer in project tapestry-5 by apache.

the class SpringModuleDef method constructObjectCreatorForApplicationContext.

private ObjectCreator constructObjectCreatorForApplicationContext(final ServiceBuilderResources resources, @Primary ApplicationContextCustomizer customizer) {
    final CustomizingContextLoader loader = new CustomizingContextLoader(customizer);
    final Runnable shutdownListener = new Runnable() {

        @Override
        public void run() {
            loader.closeWebApplicationContext(servletContext);
        }
    };
    final RegistryShutdownHub shutdownHub = resources.getService(RegistryShutdownHub.class);
    return new ObjectCreator() {

        @Override
        public Object createObject() {
            return resources.getTracker().invoke("Creating Spring ApplicationContext via ContextLoader", new Invokable<Object>() {

                @Override
                public Object invoke() {
                    resources.getLogger().info(String.format("Starting Spring (version %s)", SpringVersion.getVersion()));
                    WebApplicationContext context = loader.initWebApplicationContext(servletContext);
                    shutdownHub.addRegistryShutdownListener(shutdownListener);
                    applicationContextCreated.set(true);
                    return context;
                }
            });
        }

        @Override
        public String toString() {
            return "ObjectCreator for Spring ApplicationContext";
        }
    };
}
Also used : RegistryShutdownHub(org.apache.tapestry5.ioc.services.RegistryShutdownHub) WebApplicationContext(org.springframework.web.context.WebApplicationContext) ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext)

Example 2 with ApplicationContextCustomizer

use of org.apache.tapestry5.spring.ApplicationContextCustomizer in project tapestry-5 by apache.

the class SpringModule method addSymbolSourceAsPropertyCustomizerForSpringBeans.

@Contribute(ApplicationContextCustomizer.class)
public static void addSymbolSourceAsPropertyCustomizerForSpringBeans(OrderedConfiguration<ApplicationContextCustomizer> configuration, final SymbolSource symbolSource) {
    ApplicationContextCustomizer beanFactoryPostProcessorCustomizer = new ApplicationContextCustomizer() {

        @Override
        public void customizeApplicationContext(ServletContext servletContext, ConfigurableWebApplicationContext applicationContext) {
            applicationContext.addBeanFactoryPostProcessor(new SymbolBeanFactoryPostProcessor(symbolSource));
        }
    };
    configuration.add("BeanFactoryPostProcessorCustomizer", beanFactoryPostProcessorCustomizer);
}
Also used : ConfigurableWebApplicationContext(org.springframework.web.context.ConfigurableWebApplicationContext) ServletContext(javax.servlet.ServletContext) SymbolBeanFactoryPostProcessor(org.apache.tapestry5.internal.spring.SymbolBeanFactoryPostProcessor) ApplicationContextCustomizer(org.apache.tapestry5.spring.ApplicationContextCustomizer) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Aggregations

ConfigurableWebApplicationContext (org.springframework.web.context.ConfigurableWebApplicationContext)2 ServletContext (javax.servlet.ServletContext)1 SymbolBeanFactoryPostProcessor (org.apache.tapestry5.internal.spring.SymbolBeanFactoryPostProcessor)1 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)1 RegistryShutdownHub (org.apache.tapestry5.ioc.services.RegistryShutdownHub)1 ApplicationContextCustomizer (org.apache.tapestry5.spring.ApplicationContextCustomizer)1 WebApplicationContext (org.springframework.web.context.WebApplicationContext)1