List of usage examples for org.springframework.context.event SourceFilteringListener SourceFilteringListener
public SourceFilteringListener(Object source, ApplicationListener<?> delegate)
From source file:org.jasig.portlet.calendar.util.MockWebApplicationContextLoader.java
public ApplicationContext loadContext(String... locations) throws Exception { // Establish the portlet context and config based on the test class's MockWebApplication annotation. MockServletContext mockServletContext = new MockServletContext(configuration.webapp(), new FileSystemResourceLoader()); final ServletWrappingPortletContext portletContext = new ServletWrappingPortletContext(mockServletContext); final MockPortletConfig portletConfig = new MockPortletConfig(portletContext, configuration.name()); // Create a WebApplicationContext and initialize it with the xml and portlet configuration. final XmlPortletApplicationContext portletApplicationContext = new XmlPortletApplicationContext(); portletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, portletApplicationContext);/* w ww .ja v a2 s . c o m*/ portletApplicationContext.setPortletConfig(portletConfig); portletApplicationContext.setConfigLocations(locations); // Create a DispatcherPortlet that uses the previously established WebApplicationContext. final DispatcherPortlet dispatcherPortlet = new DispatcherPortlet() { @Override protected WebApplicationContext createPortletApplicationContext(ApplicationContext parent) { return portletApplicationContext; } }; final ViewResolver viewResolver = new MockViewResolver(); // Add the DispatcherPortlet (and anything else you want) to the context. // Note: this doesn't happen until refresh is called below. portletApplicationContext.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() { public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { beanFactory.registerResolvableDependency(DispatcherPortlet.class, dispatcherPortlet); // Register any other beans here, including a ViewResolver if you are using JSPs. beanFactory.registerResolvableDependency(ViewResolver.class, viewResolver); } }); // Have the context notify the portlet every time it is refreshed. portletApplicationContext.addApplicationListener(new SourceFilteringListener(portletApplicationContext, new ApplicationListener<ContextRefreshedEvent>() { public void onApplicationEvent(ContextRefreshedEvent event) { dispatcherPortlet.onApplicationEvent(event); } })); // Prepare the context. portletApplicationContext.refresh(); portletApplicationContext.registerShutdownHook(); // Initialize the portlet. dispatcherPortlet.setContextConfigLocation(""); dispatcherPortlet.init(portletConfig); return portletApplicationContext; }
From source file:com.github.carlomicieli.nerdmovies.MockWebApplicationContextLoader.java
@Override public ApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception { final MockServletContext servletContext = new MockServletContext(configuration.webapp(), new FileSystemResourceLoader()); final MockServletConfig servletConfig = new MockServletConfig(servletContext, configuration.name()); final AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext(); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, webContext); webContext.getEnvironment().setActiveProfiles(mergedConfig.getActiveProfiles()); webContext.setServletConfig(servletConfig); webContext.setConfigLocations(mergedConfig.getLocations()); webContext.register(mergedConfig.getClasses()); // Create a DispatcherServlet that uses the previously established // WebApplicationContext. @SuppressWarnings("serial") final DispatcherServlet dispatcherServlet = new DispatcherServlet() { @Override/* w ww .j a v a 2 s. com*/ protected WebApplicationContext createWebApplicationContext(ApplicationContext parent) { return webContext; } }; // Add the DispatcherServlet (and anything else you want) to the // context. // Note: this doesn't happen until refresh is called below. webContext.addBeanFactoryPostProcessor(new BeanFactoryPostProcessor() { @Override public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) { beanFactory.registerResolvableDependency(DispatcherServlet.class, dispatcherServlet); // Register any other beans here, including a ViewResolver if // you are using JSPs. } }); // Have the context notify the servlet every time it is refreshed. webContext.addApplicationListener( new SourceFilteringListener(webContext, new ApplicationListener<ContextRefreshedEvent>() { @Override public void onApplicationEvent(ContextRefreshedEvent event) { dispatcherServlet.onApplicationEvent(event); } })); // Prepare the context. webContext.refresh(); webContext.registerShutdownHook(); // Initialize the servlet. dispatcherServlet.setContextConfigLocation(""); dispatcherServlet.init(servletConfig); return webContext; }
From source file:org.springframework.xd.dirt.server.admin.AdminServerApplication.java
@Bean public ApplicationListener<?> xdInitializer(ApplicationContext context) { XdConfigLoggingInitializer delegate = new XdConfigLoggingInitializer(false); delegate.setEnvironment(context.getEnvironment()); return new SourceFilteringListener(context, delegate); }