Search in sources :

Example 11 with BeanDefinitionRegistry

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

the class MappingMongoConverterParserIntegrationTests method assertStrategyReferenceSetFor.

private static void assertStrategyReferenceSetFor(String beanId) {
    BeanDefinitionRegistry factory = new DefaultListableBeanFactory();
    XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
    reader.loadBeanDefinitions(new ClassPathResource("namespace/converter-custom-fieldnamingstrategy.xml"));
    BeanDefinition definition = reader.getRegistry().getBeanDefinition(beanId.concat(".mongoMappingContext"));
    BeanReference value = (BeanReference) definition.getPropertyValues().getPropertyValue("fieldNamingStrategy").getValue();
    assertThat(value.getBeanName(), is("customFieldNamingStrategy"));
}
Also used : XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) BeanReference(org.springframework.beans.factory.config.BeanReference) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ClassPathResource(org.springframework.core.io.ClassPathResource)

Example 12 with BeanDefinitionRegistry

use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project cxf by apache.

the class ConfigurerImpl method initWildcardDefinitionMap.

private void initWildcardDefinitionMap() {
    if (null != appContexts) {
        for (ApplicationContext appContext : appContexts) {
            for (String n : appContext.getBeanDefinitionNames()) {
                if (isWildcardBeanName(n)) {
                    AutowireCapableBeanFactory bf = appContext.getAutowireCapableBeanFactory();
                    BeanDefinitionRegistry bdr = (BeanDefinitionRegistry) bf;
                    BeanDefinition bd = bdr.getBeanDefinition(n);
                    String className = bd.getBeanClassName();
                    if (null != className) {
                        String orig = n;
                        if (n.charAt(0) == '*') {
                            // old wildcard
                            n = "." + n.replaceAll("\\.", "\\.");
                        }
                        try {
                            Matcher matcher = Pattern.compile(n).matcher("");
                            List<MatcherHolder> m = wildCardBeanDefinitions.get(className);
                            if (m == null) {
                                m = new ArrayList<>();
                                wildCardBeanDefinitions.put(className, m);
                            }
                            MatcherHolder holder = new MatcherHolder(orig, matcher);
                            m.add(holder);
                        } catch (PatternSyntaxException npe) {
                        // not a valid patter, we'll ignore
                        }
                    } else {
                        LogUtils.log(LOG, Level.WARNING, "WILDCARD_BEAN_ID_WITH_NO_CLASS_MSG", n);
                    }
                }
            }
        }
    }
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) Matcher(java.util.regex.Matcher) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) AutowireCapableBeanFactory(org.springframework.beans.factory.config.AutowireCapableBeanFactory) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 13 with BeanDefinitionRegistry

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

the class RemoteServicesBeanCreator method postProcessBeanFactory.

@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
    log.info("Configuring remote services");
    BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
    ApplicationContext coreContext = context.getParent();
    Map<String, Object> services = coreContext.getBeansWithAnnotation(Service.class);
    for (Map.Entry<String, Object> entry : services.entrySet()) {
        String serviceName = entry.getKey();
        Object service = entry.getValue();
        List<Class> serviceInterfaces = new ArrayList<>();
        List<Class> interfaces = ClassUtils.getAllInterfaces(service.getClass());
        for (Class intf : interfaces) {
            if (intf.getName().endsWith("Service"))
                serviceInterfaces.add(intf);
        }
        String intfName = null;
        if (serviceInterfaces.size() == 0) {
            log.error("Bean " + serviceName + " has @Service annotation but no interfaces named '*Service'. Ignoring it.");
        } else if (serviceInterfaces.size() > 1) {
            intfName = findLowestSubclassName(serviceInterfaces);
            if (intfName == null)
                log.error("Bean " + serviceName + " has @Service annotation and more than one interface named '*Service', " + "but these interfaces are not from the same hierarchy. Ignoring it.");
        } else {
            intfName = serviceInterfaces.get(0).getName();
        }
        if (intfName != null) {
            BeanDefinition definition = new RootBeanDefinition(HttpServiceExporter.class);
            MutablePropertyValues propertyValues = definition.getPropertyValues();
            propertyValues.add("service", service);
            propertyValues.add("serviceInterface", intfName);
            registry.registerBeanDefinition("/" + serviceName, definition);
            log.debug("Bean " + serviceName + " configured for export via HTTP");
        }
    }
}
Also used : ArrayList(java.util.ArrayList) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ApplicationContext(org.springframework.context.ApplicationContext) MutablePropertyValues(org.springframework.beans.MutablePropertyValues) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) Map(java.util.Map)

Example 14 with BeanDefinitionRegistry

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

the class WebRemoteProxyBeanCreator 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 15 with BeanDefinitionRegistry

use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project loc-framework by lord-of-code.

the class LocElasticJobAutoConfiguration method createSpringJobScheduler.

private void createSpringJobScheduler(String name, List<Object> argList) {
    ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) applicationContext;
    BeanDefinitionRegistry beanDefinitionRegistry = (BeanDefinitionRegistry) configurableApplicationContext.getBeanFactory();
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(SpringJobScheduler.class);
    builder.setInitMethodName("init");
    for (Object arg : argList) {
        builder.addConstructorArgValue(arg);
    }
    beanDefinitionRegistry.registerBeanDefinition(name, builder.getBeanDefinition());
    log.info("spring bean name {} register success ", name);
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry)

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