Spring Framework RootBeanDefinition - 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 RootBeanDefinition class.

This code example shows how to use the following methods:getPropertyValues, setRole, setSource
	 * Registers  an {@link HttpRequestHandlerAdapter} under a well-known 
	 * name unless already registered. 
	 */ 
	private static void registerBeanNameUrlHandlerMapping(ParserContext parserContext, Object source) {
		if (!parserContext.getRegistry().containsBeanDefinition(BEAN_NAME_URL_HANDLER_MAPPING_BEAN_NAME)){
			RootBeanDefinition beanNameMappingDef = new RootBeanDefinition(BeanNameUrlHandlerMapping.class);
			beanNameMappingDef.setSource(source);
			beanNameMappingDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
			beanNameMappingDef.getPropertyValues().add("order", 2);	// consistent with WebMvcConfigurationSupport
			parserContext.getRegistry().registerBeanDefinition(BEAN_NAME_URL_HANDLER_MAPPING_BEAN_NAME, beanNameMappingDef);
			parserContext.registerComponent(new BeanComponentDefinition(beanNameMappingDef, BEAN_NAME_URL_HANDLER_MAPPING_BEAN_NAME));
		} 
	} 
 
	/** 
	 * Registers  an {@link HttpRequestHandlerAdapter} under a well-known 
	 * name unless already registered. 
	 */ 
	private static void registerHttpRequestHandlerAdapter(ParserContext parserContext, Object source) {
		if (!parserContext.getRegistry().containsBeanDefinition(HTTP_REQUEST_HANDLER_ADAPTER_BEAN_NAME)) {
8
CodeRank
This code example shows how to use the following methods:getPropertyValues, setRole, setSource
This code example shows how to use the following methods:getPropertyValues, setRole, setSource
This code example shows how to use the following methods:setBeanClass, setRole, setSource
			beanDefs.add(registerPostProcessor(registry, def, COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
		} 
 
		// Check for JPA support, and if present add the PersistenceAnnotationBeanPostProcessor. 
		if (jpaPresent && !registry.containsBeanDefinition(PERSISTENCE_ANNOTATION_PROCESSOR_BEAN_NAME)) {
			RootBeanDefinition def = new RootBeanDefinition();
			try { 
				def.setBeanClass(ClassUtils.forName(PERSISTENCE_ANNOTATION_PROCESSOR_CLASS_NAME,
						AnnotationConfigUtils.class.getClassLoader()));
			} 
			catch (ClassNotFoundException ex) {
				throw new IllegalStateException(
						"Cannot load optional framework class: " + PERSISTENCE_ANNOTATION_PROCESSOR_CLASS_NAME, ex);
			} 
			def.setSource(source);
			beanDefs.add(registerPostProcessor(registry, def, PERSISTENCE_ANNOTATION_PROCESSOR_BEAN_NAME));
		} 
 
		return beanDefs;
	} 

7
CodeRank
This code example shows how to use the following methods:getPropertyValues
	} 
 
	@Test
	public void testNotNullConstraintAfterInitialization() { 
		GenericApplicationContext ac = new GenericApplicationContext();
		RootBeanDefinition bvpp = new RootBeanDefinition(BeanValidationPostProcessor.class);
		bvpp.getPropertyValues().add("afterInitialization", true);
		ac.registerBeanDefinition("bvpp", bvpp);
		ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class));
		ac.registerBeanDefinition("bean", new RootBeanDefinition(AfterInitConstraintBean.class));
		ac.refresh();
	} 
 
	@Test
	public void testSizeConstraint() { 
		GenericApplicationContext ac = new GenericApplicationContext();
		ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class));
		RootBeanDefinition bd = new RootBeanDefinition(NotNullConstrainedBean.class);
		bd.getPropertyValues().add("testBean", new TestBean());
		bd.getPropertyValues().add("stringValue", "s");
6
CodeRank
This code example shows how to use the following methods:getPropertyValues, setBeanClassName
This code example shows how to use the following methods:
		assertEquals("foo", (String) result1);
 
		// ### uncommenting the next line causes the test to pass for Spring > 2.0.2 ### 
		//context.removeBeanDefinition("testBean"); 
 
		context.registerBeanDefinition("testBean", new RootBeanDefinition(class2));
		Object testBean2 = context.getBean("testBean");
		Method method2 = class2.getDeclaredMethod("myMethod", new Class<?>[0]);
		Object result2 = ReflectionUtils.invokeMethod(method2, testBean2);
		assertEquals("bar", (String) result2);
	} 
 
} 
6
CodeRank
This code example shows how to use the following methods:
	} 
 
	@Test
	public void getBeanForClass() { 
		GenericApplicationContext ac = new GenericApplicationContext();
		ac.registerBeanDefinition("testBean", new RootBeanDefinition(String.class));
		ac.refresh();
 
		assertSame(ac.getBean("testBean"), ac.getBean(String.class));
		assertSame(ac.getBean("testBean"), ac.getBean(CharSequence.class));
 
		try { 
			assertSame(ac.getBean("testBean"), ac.getBean(Object.class));
			fail("Should have thrown NoUniqueBeanDefinitionException"); 
		} 
		catch (NoUniqueBeanDefinitionException ex) {
			// expected 
		} 
	} 
 
7
CodeRank
This code example shows how to use the following methods:getPropertyValues, setBeanClassName
 
	@Override 
	protected RootBeanDefinition createContainerFactory(String factoryId, Element containerEle, ParserContext parserContext,
			PropertyValues commonContainerProperties, PropertyValues specificContainerProperties) {
 
		RootBeanDefinition factoryDef = new RootBeanDefinition();
 
		String containerType = containerEle.getAttribute(CONTAINER_TYPE_ATTRIBUTE);
		String containerClass = containerEle.getAttribute(CONTAINER_CLASS_ATTRIBUTE);
		if (!"".equals(containerClass)) {
			return null; // Not supported 
		} 
		else if ("".equals(containerType) || containerType.startsWith("default")) {
			factoryDef.setBeanClassName("org.springframework.jms.config.DefaultJmsListenerContainerFactory");
		} 
		else if (containerType.startsWith("simple")) {
			factoryDef.setBeanClassName("org.springframework.jms.config.SimpleJmsListenerContainerFactory");
		} 
 
		factoryDef.getPropertyValues().addPropertyValues(commonContainerProperties);

7
CodeRank
This code example shows how to use the following methods:
public class DuplicateConfigurationClassPostProcessorTests { 
 
	@Test
	public void repro() { 
		GenericApplicationContext ctx = new GenericApplicationContext();
		ctx.registerBeanDefinition("a", new RootBeanDefinition(ConfigurationClassPostProcessor.class));
		ctx.registerBeanDefinition("b", new RootBeanDefinition(ConfigurationClassPostProcessor.class));
		ctx.registerBeanDefinition("myConfig", new RootBeanDefinition(Config.class));
		ctx.refresh();
	} 
 
	@Configuration 
	static class Config { 
		@Bean 
		public String string() {
			return "bean"; 
		} 
	} 
} 
6
CodeRank