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

Following code examples demonstrate how to use org.springframework.beans.factory.support.BeanDefinitionRegistryfrom 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.BeanDefinitionRegistryand various code implementation of this class.

	public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {

		HttpPostApiScanner scanner = new HttpPostApiScanner(registry);

		scanner.addIncludeFilter(new AnnotationTypeFilter(HttpPostApi.class));

		scanner.scan(StringUtils.tokenizeToStringArray(this.basePackages,
				ConfigurableApplicationContext.CONFIG_LOCATION_DELIMITERS));

	
	} 


	public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) {

		BeanDefinitionBuilder builder =
			BeanDefinitionBuilder.genericBeanDefinition(GemfireFunctionBeanPostProcessor.class);

		BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), registry);
	} 

    public void registerBeansForRoot(BeanDefinitionRegistry registry, RepositoryConfigurationSource configurationSource) {
        super.registerBeansForRoot(registry, configurationSource);

        if (!registry.containsBeanDefinition(BeanNames.MAPPING_CONTEXT_BEAN_NAME)) {
            RootBeanDefinition definition = new RootBeanDefinition(MarklogicMappingContext.class);
            definition.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
            definition.setSource(configurationSource.getSource());

            registry.registerBeanDefinition(BeanNames.MAPPING_CONTEXT_BEAN_NAME, definition);
        }
    } 

    }

    protected void registerBeanDefinition(BeanDefinitionRegistry registry,
                                          BeanDefinition definition,
                                          String beanName, String... aliases) {
        registerBeanDefinition(new BeanDefinitionHolder(definition, beanName, aliases), registry);
    } 

	protected BeanDefinitionBuilder getGemfireFunctionOperationsBeanDefinitionBuilder(BeanDefinitionRegistry registry) {

		String resolvedCacheBeanName = Optional.ofNullable(this.configuration.getAttribute("cache"))
			.map(String::valueOf)
			.filter(StringUtils::hasText)
			.orElse(GemfireConstants.DEFAULT_GEMFIRE_CACHE_NAME);

		Optional<String> poolBeanName = Optional.ofNullable(this.configuration.getAttribute("pool"))
			.map(String::valueOf)
			.filter(StringUtils::hasText);

		BeanDefinitionBuilder functionTemplateBuilder =
			BeanDefinitionBuilder.genericBeanDefinition(getGemfireFunctionOperationsClass());

		functionTemplateBuilder.addConstructorArgReference(resolvedCacheBeanName);

		poolBeanName.ifPresent(it -> {
			functionTemplateBuilder.addDependsOn(it);
			functionTemplateBuilder.addPropertyReference("pool", it);
		});

		return functionTemplateBuilder;
	} 

	public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
		String className = definition.getBeanClassName();
		String beanName = ClassUtils.getShortName(className);

		try {
			Class<?> clazz = Class.forName(className);
			if (clazz.isInstance(UserAttributeLoader.class)) {
				UserAttributeLoaderManager.addLoader(beanName);
				return beanName;
			}
		} catch (ClassNotFoundException e) {
		}
		return className;
	} 

    public final void registerBeanDefinitions(final AnnotationMetadata importingClassMetadata, final BeanDefinitionRegistry registry) {
        
        final GenericBeanDefinition beanDefConfProps = new GenericBeanDefinition();
        beanDefConfProps.setBeanClass(HotConfigurableProperties.class);
        registry.registerBeanDefinition("configurableProperties", beanDefConfProps);

        final GenericBeanDefinition beanDefConfHooks = new GenericBeanDefinition();
        beanDefConfHooks.setBeanClass(HotConfigurableHooks.class);
        registry.registerBeanDefinition("configurableHooks", beanDefConfHooks);

        final GenericBeanDefinition beanDefPropBeanProcessor = new GenericBeanDefinition();
        beanDefPropBeanProcessor.setBeanClass(HotConfigurablePropertyBeanProcessor.class);
        registry.registerBeanDefinition("configurablePropertyBeanProcessor", beanDefPropBeanProcessor);
    } 

	public String generateBeanName(BeanDefinition definition, BeanDefinitionRegistry registry) {
        String beanName = super.generateBeanName(definition, registry);
        if (!beanName.endsWith("Impl")) {
            return beanName;
        }
        return beanName.substring(0, beanName.length() - 4);
    } 

Advertisement
Javadoc
Interface for registries that hold bean definitions, for example RootBeanDefinition and ChildBeanDef

inition instances. Typically implemented by BeanFactories that internally work with the AbstractBeanDefinition hierarchy.

This is the only interface in Spring's bean factory packages that encapsulates registration of bean definitions. The standard BeanFactory interfaces only cover access to a fully configured factory instance.

Spring's bean definition readers expect to work on an implementation of this interface. Known implementors within the Spring core are DefaultListableBeanFactory and GenericApplicationContext. @author Juergen Hoeller @since 26.11.2003 @see org.springframework.beans.factory.config.BeanDefinition @see AbstractBeanDefinition @see RootBeanDefinition @see ChildBeanDefinition @see DefaultListableBeanFactory @see org.springframework.context.support.GenericApplicationContext @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader @see PropertiesBeanDefinitionReader

Read More
Advertisement