List of usage examples for org.springframework.web.context.support GenericWebApplicationContext getDefaultListableBeanFactory
public final DefaultListableBeanFactory getDefaultListableBeanFactory()
From source file:com.autentia.wuija.spring.TestContextLoader.java
@Override public final ConfigurableApplicationContext loadContext(String... locations) throws Exception { if (log.isDebugEnabled()) { log.debug("Loading ApplicationContext for locations [" + StringUtils.arrayToCommaDelimitedString(locations) + "]."); }// w w w . j a va2 s.c o m final GenericWebApplicationContext context = new GenericWebApplicationContext(); customizeBeanFactory(context.getDefaultListableBeanFactory()); createBeanDefinitionReader(context).loadBeanDefinitions(locations); AnnotationConfigUtils.registerAnnotationConfigProcessors(context); customizeContext(context); context.refresh(); context.registerShutdownHook(); return context; }
From source file:org.springframework.test.context.support.AbstractGenericWebContextLoader.java
/** * TODO [SPR-9864] Document overridden loadContext(MergedContextConfiguration). * * @see org.springframework.test.context.SmartContextLoader#loadContext(org.springframework.test.context.MergedContextConfiguration) *//* ww w .j a v a 2 s . co m*/ public final ConfigurableApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception { if (!(mergedConfig instanceof WebMergedContextConfiguration)) { throw new IllegalArgumentException( String.format( "Cannot load WebApplicationContext from non-web merged context configuration %s. " + "Consider annotating your test class with @WebAppConfiguration.", mergedConfig)); } WebMergedContextConfiguration webMergedConfig = (WebMergedContextConfiguration) mergedConfig; if (logger.isDebugEnabled()) { logger.debug(String.format("Loading WebApplicationContext for merged context configuration %s.", webMergedConfig)); } GenericWebApplicationContext context = new GenericWebApplicationContext(); configureWebResources(context, webMergedConfig); prepareContext(context, webMergedConfig); customizeBeanFactory(context.getDefaultListableBeanFactory(), webMergedConfig); loadBeanDefinitions(context, webMergedConfig); AnnotationConfigUtils.registerAnnotationConfigProcessors(context); customizeContext(context, webMergedConfig); context.refresh(); context.registerShutdownHook(); return context; }
From source file:org.springframework.test.context.support.WebApplicationContextLoader.java
public ApplicationContext loadContext(String... locations) throws Exception { if (logger.isDebugEnabled()) { logger.debug("Loading ApplicationContext for locations [" + StringUtils.arrayToCommaDelimitedString(locations) + "]."); }/*from w w w . j a va2 s .c om*/ GenericWebApplicationContext context = new GenericWebApplicationContext(); prepareContext(context); customizeBeanFactory(context.getDefaultListableBeanFactory()); createBeanDefinitionReader(context).loadBeanDefinitions(locations); AnnotationConfigUtils.registerAnnotationConfigProcessors(context); customizeContext(context); context.refresh(); context.registerShutdownHook(); return context; }
From source file:org.springframework.test.context.support.WebApplicationContextLoader.java
public ApplicationContext loadContext(MergedContextConfiguration config) throws Exception { GenericWebApplicationContext context = new GenericWebApplicationContext(); // Commented out until SPR-10392 is fixed and we can upgrade to Spring 3.2.3.RELEASE or higher // ApplicationContext parent = config.getParentApplicationContext(); // if(parent != null) { // context.setParent(parent); // }/*from w ww . j av a2 s . c o m*/ prepareContext(context); prepareContext(context, config); customizeBeanFactory(context.getDefaultListableBeanFactory()); createBeanDefinitionReader(context).loadBeanDefinitions(config.getLocations()); AnnotationConfigUtils.registerAnnotationConfigProcessors(context); customizeContext(context); context.refresh(); context.registerShutdownHook(); return context; }
From source file:org.springframework.test.context.web.AbstractGenericWebContextLoader.java
/** * Load a Spring {@link WebApplicationContext} from the supplied * {@link MergedContextConfiguration}./*from w ww . j a va2s. c o m*/ * <p>Implementation details: * <ul> * <li>Calls {@link #validateMergedContextConfiguration(WebMergedContextConfiguration)} * to allow subclasses to validate the supplied configuration before proceeding.</li> * <li>Creates a {@link GenericWebApplicationContext} instance.</li> * <li>If the supplied {@code MergedContextConfiguration} references a * {@linkplain MergedContextConfiguration#getParent() parent configuration}, * the corresponding {@link MergedContextConfiguration#getParentApplicationContext() * ApplicationContext} will be retrieved and * {@linkplain GenericWebApplicationContext#setParent(ApplicationContext) set as the parent} * for the context created by this method.</li> * <li>Delegates to {@link #configureWebResources} to create the * {@link MockServletContext} and set it in the {@code WebApplicationContext}.</li> * <li>Calls {@link #prepareContext} to allow for customizing the context * before bean definitions are loaded.</li> * <li>Calls {@link #customizeBeanFactory} to allow for customizing the * context's {@code DefaultListableBeanFactory}.</li> * <li>Delegates to {@link #loadBeanDefinitions} to populate the context * from the locations or classes in the supplied {@code MergedContextConfiguration}.</li> * <li>Delegates to {@link AnnotationConfigUtils} for * {@linkplain AnnotationConfigUtils#registerAnnotationConfigProcessors registering} * annotation configuration processors.</li> * <li>Calls {@link #customizeContext} to allow for customizing the context * before it is refreshed.</li> * <li>{@link ConfigurableApplicationContext#refresh Refreshes} the * context and registers a JVM shutdown hook for it.</li> * </ul> * @return a new web application context * @see org.springframework.test.context.SmartContextLoader#loadContext(MergedContextConfiguration) * @see GenericWebApplicationContext */ @Override public final ConfigurableApplicationContext loadContext(MergedContextConfiguration mergedConfig) throws Exception { Assert.isTrue(mergedConfig instanceof WebMergedContextConfiguration, () -> String .format("Cannot load WebApplicationContext from non-web merged context configuration %s. " + "Consider annotating your test class with @WebAppConfiguration.", mergedConfig)); WebMergedContextConfiguration webMergedConfig = (WebMergedContextConfiguration) mergedConfig; if (logger.isDebugEnabled()) { logger.debug(String.format("Loading WebApplicationContext for merged context configuration %s.", webMergedConfig)); } validateMergedContextConfiguration(webMergedConfig); GenericWebApplicationContext context = new GenericWebApplicationContext(); ApplicationContext parent = mergedConfig.getParentApplicationContext(); if (parent != null) { context.setParent(parent); } configureWebResources(context, webMergedConfig); prepareContext(context, webMergedConfig); customizeBeanFactory(context.getDefaultListableBeanFactory(), webMergedConfig); loadBeanDefinitions(context, webMergedConfig); AnnotationConfigUtils.registerAnnotationConfigProcessors(context); customizeContext(context, webMergedConfig); context.refresh(); context.registerShutdownHook(); return context; }