List of usage examples for org.springframework.web.context.support AnnotationConfigWebApplicationContext addBeanFactoryPostProcessor
@Override
public void addBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor)
From source file:org.lightadmin.core.config.LightAdminWebApplicationInitializer.java
private AnnotationConfigWebApplicationContext lightAdminApplicationContext( final ServletContext servletContext) { AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext(); String basePackage = configurationsBasePackage(servletContext); webApplicationContext.register(configurations(servletContext)); webApplicationContext.addBeanFactoryPostProcessor( new LightAdminBeanDefinitionRegistryPostProcessor(basePackage, servletContext)); webApplicationContext.setDisplayName("LightAdmin WebApplicationContext"); webApplicationContext.setNamespace("lightadmin"); return webApplicationContext; }
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//from ww w .j a v a 2 s . c o m 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; }