Search in sources :

Example 6 with BeanDefinitionRegistry

use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project cuba by cuba-platform.

the class PortalRemoteProxyBeanCreator method postProcessBeanFactory.

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    String useLocal = AppContext.getProperty("cuba.useLocalServiceInvocation");
    if (Boolean.valueOf(useLocal)) {
        log.info("Configuring proxy beans for local service invocations: " + services.keySet());
        BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
        for (Map.Entry<String, String> entry : services.entrySet()) {
            String name = entry.getKey();
            String serviceInterface = entry.getValue();
            BeanDefinition definition = new RootBeanDefinition(LocalServiceProxy.class);
            MutablePropertyValues propertyValues = definition.getPropertyValues();
            propertyValues.add("serviceName", name);
            propertyValues.add("serviceInterface", serviceInterface);
            registry.registerBeanDefinition(name, definition);
            log.debug("Configured proxy bean " + name + " of type " + serviceInterface);
        }
        processSubstitutions(beanFactory);
    } else {
        super.postProcessBeanFactory(beanFactory);
    }
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Map(java.util.Map)

Example 7 with BeanDefinitionRegistry

use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project cuba by cuba-platform.

the class RemoteProxyBeanCreator method postProcessBeanFactory.

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    log.info("Configuring remote proxy beans: " + services.keySet());
    BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
    for (Map.Entry<String, String> entry : services.entrySet()) {
        String name = entry.getKey();
        String serviceUrl = name;
        String serviceInterface = entry.getValue();
        BeanDefinition definition = new RootBeanDefinition(HttpServiceProxy.class);
        definition.getConstructorArgumentValues().addIndexedArgumentValue(0, serverSelector);
        MutablePropertyValues propertyValues = definition.getPropertyValues();
        propertyValues.add("serviceUrl", serviceUrl);
        propertyValues.add("serviceInterface", serviceInterface);
        registry.registerBeanDefinition(name, definition);
        log.debug("Configured remote proxy bean " + name + " of type " + serviceInterface + ", bound to " + serviceUrl);
    }
    processSubstitutions(beanFactory);
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) Map(java.util.Map)

Example 8 with BeanDefinitionRegistry

use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project dubbo by alibaba.

the class AnnotationBean method postProcessBeanFactory.

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    if (annotationPackage == null || annotationPackage.length() == 0) {
        return;
    }
    if (beanFactory instanceof BeanDefinitionRegistry) {
        try {
            // init scanner
            Class<?> scannerClass = ReflectUtils.forName("org.springframework.context.annotation.ClassPathBeanDefinitionScanner");
            Object scanner = scannerClass.getConstructor(new Class<?>[] { BeanDefinitionRegistry.class, boolean.class }).newInstance(new Object[] { (BeanDefinitionRegistry) beanFactory, true });
            // add filter
            Class<?> filterClass = ReflectUtils.forName("org.springframework.core.type.filter.AnnotationTypeFilter");
            Object filter = filterClass.getConstructor(Class.class).newInstance(Service.class);
            Method addIncludeFilter = scannerClass.getMethod("addIncludeFilter", ReflectUtils.forName("org.springframework.core.type.filter.TypeFilter"));
            addIncludeFilter.invoke(scanner, filter);
            // scan packages
            String[] packages = Constants.COMMA_SPLIT_PATTERN.split(annotationPackage);
            Method scan = scannerClass.getMethod("scan", new Class<?>[] { String[].class });
            scan.invoke(scanner, new Object[] { packages });
        } catch (Throwable e) {
        // spring 2.0
        }
    }
}
Also used : BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) Method(java.lang.reflect.Method)

Example 9 with BeanDefinitionRegistry

use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterParser method parse.

/* (non-Javadoc)
	 * @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element, org.springframework.beans.factory.xml.ParserContext)
	 */
public BeanDefinition parse(Element element, ParserContext parserContext) {
    if (parserContext.isNested()) {
        parserContext.getReaderContext().error("Mongo Converter must not be defined as nested bean.", element);
    }
    BeanDefinitionRegistry registry = parserContext.getRegistry();
    String id = element.getAttribute(AbstractBeanDefinitionParser.ID_ATTRIBUTE);
    id = StringUtils.hasText(id) ? id : DEFAULT_CONVERTER_BEAN_NAME;
    parserContext.pushContainingComponent(new CompositeComponentDefinition("Mapping Mongo Converter", element));
    BeanDefinition conversionsDefinition = getCustomConversions(element, parserContext);
    String ctxRef = potentiallyCreateMappingContext(element, parserContext, conversionsDefinition, id);
    createIsNewStrategyFactoryBeanDefinition(ctxRef, parserContext, element);
    // Need a reference to a Mongo instance
    String dbFactoryRef = element.getAttribute("db-factory-ref");
    if (!StringUtils.hasText(dbFactoryRef)) {
        dbFactoryRef = DB_FACTORY_BEAN_NAME;
    }
    // Converter
    BeanDefinitionBuilder converterBuilder = BeanDefinitionBuilder.genericBeanDefinition(MappingMongoConverter.class);
    converterBuilder.addConstructorArgReference(dbFactoryRef);
    converterBuilder.addConstructorArgReference(ctxRef);
    String typeMapperRef = element.getAttribute("type-mapper-ref");
    if (StringUtils.hasText(typeMapperRef)) {
        converterBuilder.addPropertyReference("typeMapper", typeMapperRef);
    }
    if (conversionsDefinition != null) {
        converterBuilder.addPropertyValue("customConversions", conversionsDefinition);
    }
    if (!registry.containsBeanDefinition("indexOperationsProvider")) {
        BeanDefinitionBuilder indexOperationsProviderBuilder = BeanDefinitionBuilder.genericBeanDefinition("org.springframework.data.mongodb.core.DefaultIndexOperationsProvider");
        indexOperationsProviderBuilder.addConstructorArgReference(dbFactoryRef);
        indexOperationsProviderBuilder.addConstructorArgValue(BeanDefinitionBuilder.genericBeanDefinition(QueryMapper.class).addConstructorArgReference(id).getBeanDefinition());
        parserContext.registerBeanComponent(new BeanComponentDefinition(indexOperationsProviderBuilder.getBeanDefinition(), "indexOperationsProvider"));
    }
    try {
        registry.getBeanDefinition(INDEX_HELPER_BEAN_NAME);
    } catch (NoSuchBeanDefinitionException ignored) {
        BeanDefinitionBuilder indexHelperBuilder = BeanDefinitionBuilder.genericBeanDefinition(MongoPersistentEntityIndexCreator.class);
        indexHelperBuilder.addConstructorArgReference(ctxRef);
        indexHelperBuilder.addConstructorArgReference("indexOperationsProvider");
        indexHelperBuilder.addDependsOn(ctxRef);
        parserContext.registerBeanComponent(new BeanComponentDefinition(indexHelperBuilder.getBeanDefinition(), INDEX_HELPER_BEAN_NAME));
    }
    BeanDefinition validatingMongoEventListener = potentiallyCreateValidatingMongoEventListener(element, parserContext);
    if (validatingMongoEventListener != null) {
        parserContext.registerBeanComponent(new BeanComponentDefinition(validatingMongoEventListener, VALIDATING_EVENT_LISTENER_BEAN_NAME));
    }
    parserContext.registerBeanComponent(new BeanComponentDefinition(converterBuilder.getBeanDefinition(), id));
    parserContext.popAndRegisterContainingComponent();
    return null;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) MongoPersistentEntityIndexCreator(org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator) CompositeComponentDefinition(org.springframework.beans.factory.parsing.CompositeComponentDefinition) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) AbstractBeanDefinition(org.springframework.beans.factory.support.AbstractBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) GenericBeanDefinition(org.springframework.beans.factory.support.GenericBeanDefinition) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Example 10 with BeanDefinitionRegistry

use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-data-mongodb by spring-projects.

the class MappingMongoConverterParserIntegrationTests method rejectsInvalidFieldNamingStrategyConfiguration.

// DATAMONGO-866
@Test
public void rejectsInvalidFieldNamingStrategyConfiguration() {
    exception.expect(BeanDefinitionParsingException.class);
    exception.expectMessage("abbreviation");
    exception.expectMessage("field-naming-strategy-ref");
    BeanDefinitionRegistry factory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
    reader.loadBeanDefinitions(new ClassPathResource("namespace/converter-invalid.xml"));
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Aggregations

BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)72 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)29 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)17 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)13 Test (org.junit.jupiter.api.Test)12 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)12 SimpleBeanDefinitionRegistry (org.springframework.beans.factory.support.SimpleBeanDefinitionRegistry)11 Map (java.util.Map)9 AnnotatedGenericBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedGenericBeanDefinition)9 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)6 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)5 Test (org.junit.Test)4 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)4 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)4 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)4 DefaultListableBeanFactory (org.springframework.beans.factory.support.DefaultListableBeanFactory)4 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)4 ApplicationContext (org.springframework.context.ApplicationContext)4 ClassPathResource (org.springframework.core.io.ClassPathResource)4 HashMap (java.util.HashMap)3