Java Code Examples for org.springframework.beans.factory.support.BeanDefinitionBuilder

Following code examples demonstrate how to use org.springframework.beans.factory.support.BeanDefinitionBuilderfrom spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.beans.factory.support.BeanDefinitionBuilderand various code implementation of this class.

	public void postProcess(BeanDefinitionBuilder builder, RepositoryConfigurationSource source) {

		if (fallbackMappingContextCreated) {
			builder.addPropertyReference("mappingContext", BeanNames.MAPPING_CONTEXT_BEAN_NAME);
		}
	} 


	public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) {

		AnnotationAttributes attributes = config.getAttributes();

		builder.addPropertyReference("mongoOperations", attributes.getString("mongoTemplateRef"));
		builder.addPropertyValue("createIndexesForQueryMethods", attributes.getBoolean("createIndexesForQueryMethods"));
	} 

	public void postProcess(BeanDefinitionBuilder builder, XmlRepositoryConfigurationSource config) {

		Element element = config.getElement();

		ParsingUtils.setPropertyReference(builder, element, MONGO_TEMPLATE_REF, "mongoOperations");
		ParsingUtils.setPropertyValue(builder, element, CREATE_QUERY_INDEXES, "createIndexesForQueryMethods");
	} 

	protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
		
		List<?> propertyElements = DomUtils.getChildElementsByTagName(element, "property");
		for (Iterator<?> iterator = propertyElements.iterator(); iterator.hasNext();) {
			Element property = (Element) iterator.next();
			parserContext.getDelegate().parsePropertyElement(property, builder.getBeanDefinition());
		}
		
		builder.addPropertyValue("ignoreResourceNotFound", true);
		builder.addPropertyValue("ignoreUnresolvablePlaceholders", true);
	} 

    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {


        BeanDefinitionBuilder builder = rootBeanDefinition(TestBeanPostProcessor.class);
        AbstractBeanDefinition beanDefinition = builder.getBeanDefinition();
        BeanDefinitionReaderUtils.registerWithGeneratedName(beanDefinition, registry);
        log.info("TestScanRegistrar {}", "registerBeanDefinitionsregisterBeanDefinitionsregisterBeanDefinitionsregisterBeanDefinitions");

    } 

	public void postProcess(BeanDefinitionBuilder builder, XmlRepositoryConfigurationSource config) {

		Element element = config.getElement();

				.orElse(DefaultBeanNames.DATA_TEMPLATE);

		builder.addPropertyReference("cassandraTemplate", cassandraTemplateRef);
	} 

	public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) {

		String cassandraTemplateRef = config.getAttributes().getString("cassandraTemplateRef");

		if (StringUtils.hasText(cassandraTemplateRef)) {
			builder.addPropertyReference("cassandraTemplate", cassandraTemplateRef);
		}
	} 

    protected void addPropertyValueFromElement(String id, Element element, BeanDefinitionBuilder bean) {
        String beanElement = element.getAttribute(id);
        bean.addPropertyValue(id, beanElement);
    } 

    protected void addPropertyReferenceFromElement(String id, Element element, BeanDefinitionBuilder bean) {
        String beanElement = element.getAttribute(id);
        bean.addPropertyReference(id, beanElement);
    } 

    public void doParse(Element element, BeanDefinitionBuilder builder) {
        builder.addPropertyReference("bundleContext", "bundleContext");
        prepareInjection(element, builder);
        builder.setLazyInit(false);
        builder.setInitMethodName("start");
        builder.setDestroyMethodName("stop");
        super.doParse(element, builder);
    } 

    
    protected void addPropertyValueFromElement(String id, String injectionId, Element element,
            BeanDefinitionBuilder bean) {
        String beanElement = element.getAttribute(id);
        bean.addPropertyValue(injectionId, beanElement);
    } 

    private void registerAsyncClientHttpRequestFactory(final String id) {
        registry.registerIfAbsent(id, AsyncClientHttpRequestFactory.class, () -> {
            log.debug("Client [{}]: Registering mocked AsyncClientHttpRequestFactory", id);
            final BeanDefinitionBuilder factory = genericBeanDefinition(AsyncClientHttpRequestFactory.class);
            factory.addDependsOn(RiptideTestAutoConfiguration.SERVER_BEAN_NAME);
            factory.setFactoryMethodOnBean("getAsyncRequestFactory", RiptideTestAutoConfiguration.TEMPLATE_BEAN_NAME);
            return factory;
        });
    } 

	protected void setDefaultProperties(BeanDefinitionBuilder builder) {

		super.setDefaultProperties(builder);

		addRequiredPropertyValue(builder, "schemaAction", SchemaAction.NONE.name());
		addRequiredPropertyReference(builder, "converter", DefaultBeanNames.CONVERTER);
	} 

	protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {

		super.doParse(element, parserContext, builder);

		CassandraMappingXmlBeanFactoryPostProcessorRegistrar.ensureRegistration(element, parserContext);
	} 

	public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) {

		AnnotationAttributes attributes = config.getAttributes();

		builder.addPropertyReference("neo4jTemplate", attributes.getString(ANN_NEO4J_TEMPLATE_REF));
		builder.addPropertyReference("neo4jMappingContext", DEFAULT_NEO4J_MAPPING_CONTEXT_REF);
	} 

	public void postProcess(BeanDefinitionBuilder builder, XmlRepositoryConfigurationSource config) {

		Element element = config.getElement();

		String templateRef = element.getAttribute(NEO4J_TEMPLATE_REF);
		templateRef = StringUtils.hasText(templateRef) ? templateRef : DEFAULT_NEO4J_TEMPLATE_REF;
		builder.addPropertyReference("neo4jTemplate", templateRef);
		builder.addPropertyReference("neo4jMappingContext", DEFAULT_NEO4J_MAPPING_CONTEXT_REF);
	} 

	protected void doParse(Element element, BeanDefinitionBuilder builder) {
		String name=element.getAttribute("name");
		String age=element.getAttribute("age");
		String id = element.getAttribute("id");
		if (StringUtils.hasText(id)) {  
			builder.addPropertyValue("id", id);  
        }  
        if (StringUtils.hasText(name)) {  
        	builder.addPropertyValue("name", name);  
        }  
        if (StringUtils.hasText(age)) {  
        	builder.addPropertyValue("age", Integer.valueOf(age));  
        } 
	} 

	public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) {

		AnnotationAttributes attributes = config.getAttributes();
		builder.addPropertyReference("crateOperations", attributes.getString("crateTemplateRef"));
	} 

	public void postProcess(BeanDefinitionBuilder builder, XmlRepositoryConfigurationSource config) {

		Element element = config.getElement();
		builder.addPropertyReference("crateOperations", element.getAttribute("crate-template-ref"));
	} 

	public void postProcess(BeanDefinitionBuilder builder, AnnotationRepositoryConfigurationSource config) {

		AnnotationAttributes attributes = config.getAttributes();
		builder.addPropertyReference("elasticsearchOperations", attributes.getString("elasticsearchTemplateRef"));
	} 

	public void postProcess(BeanDefinitionBuilder builder, XmlRepositoryConfigurationSource config) {

		Element element = config.getElement();
		builder.addPropertyReference("elasticsearchOperations", element.getAttribute("elasticsearch-template-ref"));
	} 

Advertisement
Javadoc
Programmatic means of constructing org.springframework.beans.factory.config.BeanDefinition BeanDefin

itions using the builder pattern. Intended primarily for use when implementing Spring 2.0 org.springframework.beans.factory.xml.NamespaceHandler NamespaceHandlers. @author Rod Johnson @author Rob Harrop @author Juergen Hoeller @since 2.0

Read More
Advertisement