Spring Framework MergedContextConfiguration - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Spring Framework MergedContextConfiguration class.

This code example shows how to use the following methods:getActiveProfiles, getClasses, getLocations, getParentApplicationContext
        } 
        WebMergedContextConfiguration webMergedConfig = (WebMergedContextConfiguration) mergedConfig; 
 
        AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); 
 
        ApplicationContext parent = mergedConfig.getParentApplicationContext(); 
        if (parent != null) { 
            context.setParent(parent); 
        } 
        configureWebResources(context, webMergedConfig); 
        context.getEnvironment().setActiveProfiles(mergedConfig.getActiveProfiles()); 
        new YamlServletProfileInitializerContextInitializer().initializeContext(context, environmentConfigDefaults()); 
        context.setConfigLocations(mergedConfig.getLocations()); 
        context.register(mergedConfig.getClasses()); 
        context.refresh(); 
        context.registerShutdownHook(); 
        return context; 
    } 
 
    protected String environmentConfigDefaults() { 
7
CodeRank
This code example shows how to use the following methods:
This code example shows how to use the following methods:hasClasses, hasLocations
 */ 
public class HybridContextLoader extends AbstractGenericContextLoader {
 
	@Override 
	protected void validateMergedContextConfiguration(MergedContextConfiguration mergedConfig) {
		Assert.isTrue(mergedConfig.hasClasses() || mergedConfig.hasLocations(), getClass().getSimpleName()
				+ " requires either classes or locations"); 
	} 
 
	@Override 
	public void processContextConfiguration(ContextConfigurationAttributes configAttributes) {
		// Detect default XML configuration files: 
		super.processContextConfiguration(configAttributes);
 
		// Detect default configuration classes: 
		if (!configAttributes.hasClasses() && isGenerateDefaultLocations()) {
			configAttributes.setClasses(detectDefaultConfigurationClasses(configAttributes.getDeclaringClass()));
		} 
	} 
 
7
CodeRank
This code example shows how to use the following methods:
This code example shows how to use the following methods:
	@Test
	public void configMustNotContainLocations() throws Exception {
		expectedException.expect(IllegalStateException.class);
		expectedException.expectMessage(containsString("does not support resource locations"));
 
		MergedContextConfiguration mergedConfig = new MergedContextConfiguration(getClass(),
			new String[] { "config.xml" }, EMPTY_CLASS_ARRAY, EMPTY_STRING_ARRAY, contextLoader);
		contextLoader.loadContext(mergedConfig);
	} 
 
	@Test
	public void detectDefaultConfigurationClassesForAnnotatedInnerClass() { 
		Class<?>[] configClasses = contextLoader.detectDefaultConfigurationClasses(ContextConfigurationInnerClassTestCase.class);
		assertNotNull(configClasses);
		assertEquals("annotated static ContextConfiguration should be considered.", 1, configClasses.length);
 
		configClasses = contextLoader.detectDefaultConfigurationClasses(AnnotatedFooConfigInnerClassTestCase.class);
		assertNotNull(configClasses);
		assertEquals("annotated static FooConfig should be considered.", 1, configClasses.length);
	} 
6
CodeRank
This code example shows how to use the following methods:getLocations
	 * @param mergedConfig the merged context configuration 
	 * @see #loadContext(MergedContextConfiguration) 
	 * @since 3.1 
	 */ 
	protected void loadBeanDefinitions(GenericApplicationContext context, MergedContextConfiguration mergedConfig) {
		createBeanDefinitionReader(context).loadBeanDefinitions(mergedConfig.getLocations());
	} 
 
	/** 
	 * Factory method for creating a new {@link BeanDefinitionReader} for loading 
	 * bean definitions into the supplied {@link GenericApplicationContext context}. 
	 * 
	 * @param context the context for which the {@code BeanDefinitionReader} 
	 * should be created 
	 * @return a {@code BeanDefinitionReader} for the supplied context 
	 * @see #loadContext(String...) 
	 * @see #loadBeanDefinitions 
	 * @see BeanDefinitionReader 
	 * @since 2.5 
	 */ 
5
CodeRank
This code example shows how to use the following methods:getTestClass
	 * @param mergedConfig the merged configuration from which the classes should be retrieved 
	 */ 
	public static void handleClusterInject(GenericApplicationContext context,
			MergedContextConfiguration mergedConfig) {
		final Class<MiniHadoopCluster> annotationType = MiniHadoopCluster.class;
		Class<?> testClass = mergedConfig.getTestClass();
		boolean hasMiniHadoopCluster = testClass.isAnnotationPresent(annotationType);
		MiniHadoopCluster annotation = testClass.getAnnotation(annotationType);
		 
		if (hasMiniHadoopCluster) {
			String clusterName = annotation.clusterName();
			String configName = annotation.configName();
			String id = annotation.id();
			int nodeCount = annotation.nodes();
			 
			BeanDefinitionBuilder builder = BeanDefinitionBuilder
					.genericBeanDefinition(HadoopClusterDelegatingFactoryBean.class);
			builder.addPropertyValue("id", id);
			builder.addPropertyValue("nodes", nodeCount);
			context.registerBeanDefinition(clusterName, builder.getBeanDefinition());
4
CodeRank
This code example shows how to use the following methods:getTestClass
	 * @param context the context in which the configuration classes should be registered 
	 * @param mergedConfig the merged configuration from which the classes should be retrieved 
	 */ 
	public static void handleClusterInject(GenericApplicationContext context,
			MergedContextConfiguration mergedConfig) {
		Class<?> testClass = mergedConfig.getTestClass();
		AnnotationDescriptor<MiniYarnCluster> annotationDescriptor = MetaAnnotationUtils.findAnnotationDescriptor(
				testClass, MiniYarnCluster.class);
 
		if (annotationDescriptor != null && annotationDescriptor.getAnnotation() != null) {
			String clusterName = annotationDescriptor.getAnnotationAttributes().getString("clusterName");
			String configName = annotationDescriptor.getAnnotationAttributes().getString("configName");
			String id = annotationDescriptor.getAnnotationAttributes().getString("id");
			int nodeCount = annotationDescriptor.getAnnotationAttributes().getNumber("nodes").intValue();
 
			BeanDefinitionBuilder builder = BeanDefinitionBuilder
					.genericBeanDefinition(ClusterDelegatingFactoryBean.class);
			builder.addPropertyValue("id", id);
			builder.addPropertyValue("nodes", nodeCount);
			context.registerBeanDefinition(clusterName, builder.getBeanDefinition());
4
CodeRank
This code example shows how to use the following methods:getLocations
		//		} 
 
		prepareContext(context); 
		prepareContext(context, config); 
		customizeBeanFactory(context.getDefaultListableBeanFactory()); 
		createBeanDefinitionReader(context).loadBeanDefinitions(config.getLocations()); 
		AnnotationConfigUtils.registerAnnotationConfigProcessors(context); 
		customizeContext(context); 
		context.refresh(); 
		context.registerShutdownHook(); 
 
		return context; 
	} 
 
} 
3
CodeRank
See Code Examples for Spring Framework MergedContextConfiguration Methods: