Search in sources :

Example 56 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition in project invesdwin-context-persistence by subes.

the class JpaRepositoryScanContextLocation method scanForJpaRepositories.

private Map<Class<?>, Set<Class<?>>> scanForJpaRepositories(final String basePackage) {
    final Map<Class<?>, Set<Class<?>>> jpaRepositories = new HashMap<Class<?>, Set<Class<?>>>();
    final ClassPathScanner scanner = new ClassPathScanner().withInterfacesOnly();
    scanner.addIncludeFilter(new AssignableTypeFilter(JpaRepository.class));
    final Set<BeanDefinition> candidateComponents = scanner.findCandidateComponents(basePackage);
    for (final BeanDefinition bd : candidateComponents) {
        final String beanClassName = bd.getBeanClassName();
        final Class<?> repositoryClass = Reflections.classForName(beanClassName);
        if (!IDao.class.isAssignableFrom(repositoryClass)) {
            final Class<?>[] typeArguments = Reflections.resolveTypeArguments(repositoryClass, JpaRepository.class);
            Assertions.assertThat(typeArguments.length).isEqualTo(2);
            final Class<?> entity = typeArguments[0];
            Set<Class<?>> set = jpaRepositories.get(entity);
            if (set == null) {
                set = new HashSet<Class<?>>();
                jpaRepositories.put(entity, set);
            }
            Assertions.assertThat(set.add(repositoryClass)).isTrue();
        }
    }
    return jpaRepositories;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) IDao(de.invesdwin.context.persistence.jpa.api.dao.IDao) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ClassPathScanner(de.invesdwin.util.classpath.ClassPathScanner) JpaRepository(org.springframework.data.jpa.repository.JpaRepository) AssignableTypeFilter(org.springframework.core.type.filter.AssignableTypeFilter)

Example 57 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition in project POL-POM-5 by PhoenicisOrg.

the class DTOContractTest method findAllDTOs.

private static List<DTOContainer<?>> findAllDTOs() throws ClassNotFoundException {
    final List<DTOContainer<?>> fondJsonCreatorClasses = new ArrayList<>();
    final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);
    scanner.addIncludeFilter((metadataReader, metadataReaderFactory) -> true);
    final Stream<String> classNamesStream = scanner.findCandidateComponents("org.phoenicis").stream().map(BeanDefinition::getBeanClassName);
    final Iterable<String> classNames = classNamesStream::iterator;
    for (String className : classNames) {
        final Class<?> clazz = Class.forName(className);
        if (isJsonClass(clazz)) {
            fondJsonCreatorClasses.add(new DTOContainer<>(clazz));
        }
    }
    return fondJsonCreatorClasses;
}
Also used : ClassPathScanningCandidateComponentProvider(org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 58 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition in project POL-POM-5 by PhoenicisOrg.

the class TranslatableContractTest method findAllTranslatables.

private static List<TranslatableContainer<?>> findAllTranslatables() throws ClassNotFoundException {
    final List<TranslatableContainer<?>> foundClasses = new ArrayList<>();
    final ClassPathScanningCandidateComponentProvider scanner = new ClassPathScanningCandidateComponentProvider(true);
    scanner.addIncludeFilter((metadataReader, metadataReaderFactory) -> true);
    final Stream<String> classNamesStream = scanner.findCandidateComponents("org.phoenicis").stream().map(BeanDefinition::getBeanClassName);
    final Iterable<String> classNames = classNamesStream::iterator;
    for (String className : classNames) {
        final Class<?> clazz = Class.forName(className);
        if (isTranslatable(clazz)) {
            foundClasses.add(new TranslatableContainer<>(clazz));
        }
    }
    return foundClasses;
}
Also used : ClassPathScanningCandidateComponentProvider(org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 59 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition in project apollo by ctripcorp.

the class SpringValueDefinitionProcessor method processPropertyValues.

private void processPropertyValues(BeanDefinitionRegistry beanRegistry) {
    if (!PROPERTY_VALUES_PROCESSED_BEAN_FACTORIES.add(beanRegistry)) {
        // already initialized
        return;
    }
    if (!beanName2SpringValueDefinitions.containsKey(beanRegistry)) {
        beanName2SpringValueDefinitions.put(beanRegistry, LinkedListMultimap.<String, SpringValueDefinition>create());
    }
    Multimap<String, SpringValueDefinition> springValueDefinitions = beanName2SpringValueDefinitions.get(beanRegistry);
    String[] beanNames = beanRegistry.getBeanDefinitionNames();
    for (String beanName : beanNames) {
        BeanDefinition beanDefinition = beanRegistry.getBeanDefinition(beanName);
        MutablePropertyValues mutablePropertyValues = beanDefinition.getPropertyValues();
        List<PropertyValue> propertyValues = mutablePropertyValues.getPropertyValueList();
        for (PropertyValue propertyValue : propertyValues) {
            Object value = propertyValue.getValue();
            if (!(value instanceof TypedStringValue)) {
                continue;
            }
            String placeholder = ((TypedStringValue) value).getValue();
            Set<String> keys = placeholderHelper.extractPlaceholderKeys(placeholder);
            if (keys.isEmpty()) {
                continue;
            }
            for (String key : keys) {
                springValueDefinitions.put(beanName, new SpringValueDefinition(key, placeholder, propertyValue.getName()));
            }
        }
    }
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) PropertyValue(org.springframework.beans.PropertyValue) TypedStringValue(org.springframework.beans.factory.config.TypedStringValue) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 60 with BeanDefinition

use of org.springframework.beans.factory.config.BeanDefinition in project apollo by ctripcorp.

the class PlaceholderHelper method resolvePropertyValue.

/**
 * Resolve placeholder property values, e.g.
 * <br />
 * <br />
 * "${somePropertyValue}" -> "the actual property value"
 */
public Object resolvePropertyValue(ConfigurableBeanFactory beanFactory, String beanName, String placeholder) {
    // resolve string value
    String strVal = beanFactory.resolveEmbeddedValue(placeholder);
    BeanDefinition bd = (beanFactory.containsBean(beanName) ? beanFactory.getMergedBeanDefinition(beanName) : null);
    // resolve expressions like "#{systemProperties.myProp}"
    return evaluateBeanDefinitionString(beanFactory, strVal, bd);
}
Also used : BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Aggregations

BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)601 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)188 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)116 Test (org.junit.jupiter.api.Test)112 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)89 Element (org.w3c.dom.Element)72 Test (org.junit.Test)66 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)60 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)53 ClassPathScanningCandidateComponentProvider (org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider)41 ManagedList (org.springframework.beans.factory.support.ManagedList)39 AnnotatedBeanDefinition (org.springframework.beans.factory.annotation.AnnotatedBeanDefinition)36 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)35 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)34 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)34 AnnotationTypeFilter (org.springframework.core.type.filter.AnnotationTypeFilter)31 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)30 Method (java.lang.reflect.Method)28 ArrayList (java.util.ArrayList)28 Map (java.util.Map)27