/** * Customize the {@link ConfigurableApplicationContext} created by this * {@code ContextLoader} <em>after</em> bean definitions have been loaded * into the context but <em>before</em> the context has been refreshed. * <p>The default implementation delegates to all * {@link MergedContextConfiguration#getContextCustomizers context customizers} * that have been registered with the supplied {@code mergedConfig}. * @param context the newly created application context * @param mergedConfig the merged context configuration * @since 4.3 */ protected void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) { for (ContextCustomizer contextCustomizer : mergedConfig.getContextCustomizers()) { contextCustomizer.customizeContext(context, mergedConfig); } }
if (!mergedConfig.getContextInitializerClasses().isEmpty() || !mergedConfig.getContextCustomizers().isEmpty()) { return delegateLoading(getAnnotationConfigLoader(), mergedConfig);
/** * Customize the {@link ConfigurableApplicationContext} created by this * {@code ContextLoader} <em>after</em> bean definitions have been loaded * into the context but <em>before</em> the context has been refreshed. * <p>The default implementation delegates to all * {@link MergedContextConfiguration#getContextCustomizers context customizers} * that have been registered with the supplied {@code mergedConfig}. * @param context the newly created application context * @param mergedConfig the merged context configuration * @since 4.3 */ protected void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) { for (ContextCustomizer contextCustomizer : mergedConfig.getContextCustomizers()) { contextCustomizer.customizeContext(context, mergedConfig); } }
/** * Customize the {@link ConfigurableApplicationContext} created by this * {@code ContextLoader} <em>after</em> bean definitions have been loaded * into the context but <em>before</em> the context has been refreshed. * <p>The default implementation delegates to all * {@link MergedContextConfiguration#getContextCustomizers context customizers} * that have been registered with the supplied {@code mergedConfig}. * @param context the newly created application context * @param mergedConfig the merged context configuration * @since 4.3 */ protected void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) { for (ContextCustomizer contextCustomizer : mergedConfig.getContextCustomizers()) { contextCustomizer.customizeContext(context, mergedConfig); } }
/** * Return the {@link ApplicationContextInitializer initializers} that will be applied * to the context. By default this method will adapt {@link ContextCustomizer context * customizers}, add {@link SpringApplication#getInitializers() application * initializers} and add * {@link MergedContextConfiguration#getContextInitializerClasses() initializers * specified on the test}. * @param config the source context configuration * @param application the application instance * @return the initializers to apply * @since 2.0.0 */ protected List<ApplicationContextInitializer<?>> getInitializers( MergedContextConfiguration config, SpringApplication application) { List<ApplicationContextInitializer<?>> initializers = new ArrayList<>(); for (ContextCustomizer contextCustomizer : config.getContextCustomizers()) { initializers.add(new ContextCustomizerAdapter(contextCustomizer, config)); } initializers.addAll(application.getInitializers()); for (Class<? extends ApplicationContextInitializer<?>> initializerClass : config .getContextInitializerClasses()) { initializers.add(BeanUtils.instantiateClass(initializerClass)); } if (config.getParent() != null) { initializers.add(new ParentContextApplicationContextInitializer( config.getParentApplicationContext())); } return initializers; }
if (!mergedConfig.getContextInitializerClasses().isEmpty() || !mergedConfig.getContextCustomizers().isEmpty()) { return delegateLoading(getAnnotationConfigLoader(), mergedConfig);
if (!mergedConfig.getContextInitializerClasses().isEmpty() || !mergedConfig.getContextCustomizers().isEmpty()) { return delegateLoading(getAnnotationConfigLoader(), mergedConfig);
/** * Create a new {@link MergedContextConfiguration} with different classes and * properties. * @param mergedConfig the source config * @param classes the replacement classes * @param propertySourceProperties the replacement properties * @return a new {@link MergedContextConfiguration} */ protected final MergedContextConfiguration createModifiedConfig( MergedContextConfiguration mergedConfig, Class<?>[] classes, String[] propertySourceProperties) { return new MergedContextConfiguration(mergedConfig.getTestClass(), mergedConfig.getLocations(), classes, mergedConfig.getContextInitializerClasses(), mergedConfig.getActiveProfiles(), mergedConfig.getPropertySourceLocations(), propertySourceProperties, mergedConfig.getContextCustomizers(), mergedConfig.getContextLoader(), getCacheAwareContextLoaderDelegate(), mergedConfig.getParent()); }