org.springframework.beans.factory.annotation.InjectionMetadata Java Examples

The following examples show how to use org.springframework.beans.factory.annotation.InjectionMetadata. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractArmeriaBeanPostProcessor.java    From armeria with Apache License 2.0 6 votes vote down vote up
protected InjectionMetadata findLocalArmeriaPortMetadata(
        String beanName, Class<?> clazz, @Nullable PropertyValues pvs) {
    final String cacheKey = Strings.isNullOrEmpty(beanName) ? beanName : clazz.getName();
    InjectionMetadata metadata = injectionMetadataCache.get(cacheKey);
    if (InjectionMetadata.needsRefresh(metadata, clazz)) {
        synchronized (injectionMetadataCache) {
            metadata = injectionMetadataCache.get(cacheKey);
            if (InjectionMetadata.needsRefresh(metadata, clazz)) {
                if (metadata != null) {
                    metadata.clear(pvs);
                }
                metadata = buildLocalArmeriaPortMetadata(clazz);
                injectionMetadataCache.put(cacheKey, metadata);
            }
        }
    }
    return metadata;
}
 
Example #2
Source File: PersistenceAnnotationBeanPostProcessor.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private InjectionMetadata findPersistenceMetadata(String beanName, final Class<?> clazz, @Nullable PropertyValues pvs) {
	// Fall back to class name as cache key, for backwards compatibility with custom callers.
	String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
	// Quick check on the concurrent map first, with minimal locking.
	InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
	if (InjectionMetadata.needsRefresh(metadata, clazz)) {
		synchronized (this.injectionMetadataCache) {
			metadata = this.injectionMetadataCache.get(cacheKey);
			if (InjectionMetadata.needsRefresh(metadata, clazz)) {
				if (metadata != null) {
					metadata.clear(pvs);
				}
				metadata = buildPersistenceMetadata(clazz);
				this.injectionMetadataCache.put(cacheKey, metadata);
			}
		}
	}
	return metadata;
}
 
Example #3
Source File: CommonAnnotationBeanPostProcessor.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private InjectionMetadata findResourceMetadata(String beanName, final Class<?> clazz, @Nullable PropertyValues pvs) {
	// Fall back to class name as cache key, for backwards compatibility with custom callers.
	String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
	// Quick check on the concurrent map first, with minimal locking.
	InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
	if (InjectionMetadata.needsRefresh(metadata, clazz)) {
		synchronized (this.injectionMetadataCache) {
			metadata = this.injectionMetadataCache.get(cacheKey);
			if (InjectionMetadata.needsRefresh(metadata, clazz)) {
				if (metadata != null) {
					metadata.clear(pvs);
				}
				metadata = buildResourceMetadata(clazz);
				this.injectionMetadataCache.put(cacheKey, metadata);
			}
		}
	}
	return metadata;
}
 
Example #4
Source File: CommonAnnotationBeanPostProcessor.java    From java-technology-stack with MIT License 6 votes vote down vote up
private InjectionMetadata findResourceMetadata(String beanName, final Class<?> clazz, @Nullable PropertyValues pvs) {
	// Fall back to class name as cache key, for backwards compatibility with custom callers.
	String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
	// Quick check on the concurrent map first, with minimal locking.
	InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
	if (InjectionMetadata.needsRefresh(metadata, clazz)) {
		synchronized (this.injectionMetadataCache) {
			metadata = this.injectionMetadataCache.get(cacheKey);
			if (InjectionMetadata.needsRefresh(metadata, clazz)) {
				if (metadata != null) {
					metadata.clear(pvs);
				}
				metadata = buildResourceMetadata(clazz);
				this.injectionMetadataCache.put(cacheKey, metadata);
			}
		}
	}
	return metadata;
}
 
Example #5
Source File: PersistenceAnnotationBeanPostProcessor.java    From java-technology-stack with MIT License 6 votes vote down vote up
private InjectionMetadata findPersistenceMetadata(String beanName, final Class<?> clazz, @Nullable PropertyValues pvs) {
	// Fall back to class name as cache key, for backwards compatibility with custom callers.
	String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
	// Quick check on the concurrent map first, with minimal locking.
	InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
	if (InjectionMetadata.needsRefresh(metadata, clazz)) {
		synchronized (this.injectionMetadataCache) {
			metadata = this.injectionMetadataCache.get(cacheKey);
			if (InjectionMetadata.needsRefresh(metadata, clazz)) {
				if (metadata != null) {
					metadata.clear(pvs);
				}
				metadata = buildPersistenceMetadata(clazz);
				this.injectionMetadataCache.put(cacheKey, metadata);
			}
		}
	}
	return metadata;
}
 
Example #6
Source File: CommonAnnotationBeanPostProcessor.java    From brpc-java with Apache License 2.0 6 votes vote down vote up
/**
 * To parse all method to find out annotation info.
 *
 * @param clazz target class
 * @param annotions the annotions
 * @param elements injected element of all methods
 */
protected void parseMethods(final Class<?> clazz, final List<Class<? extends Annotation>> annotions,
        final LinkedList<InjectionMetadata.InjectedElement> elements) {
    ReflectionUtils.doWithMethods(clazz, new ReflectionUtils.MethodCallback() {
        public void doWith(Method method) {
            for (Class<? extends Annotation> anno : annotions) {
                Annotation annotation = method.getAnnotation(anno);
                if (annotation != null && method.equals(ClassUtils.getMostSpecificMethod(method, clazz))) {
                    if (Modifier.isStatic(method.getModifiers())) {
                        throw new IllegalStateException("Autowired annotation is not supported on static methods");
                    }
                    if (method.getParameterTypes().length == 0) {
                        throw new IllegalStateException(
                                "Autowired annotation requires at least one argument: " + method);
                    }
                    PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
                    elements.add(new AutowiredMethodElement(method, annotation, pd));
                }
            }
        }
    });
}
 
Example #7
Source File: CommonAnnotationBeanPostProcessor.java    From brpc-java with Apache License 2.0 6 votes vote down vote up
/**
 * To parse all field to find out annotation info.
 *
 * @param clazz target class
 * @param annotations the annotations
 * @param elements injected element of all fields
 */
protected void parseFields(final Class<?> clazz, final List<Class<? extends Annotation>> annotations,
        final LinkedList<InjectionMetadata.InjectedElement> elements) {
    ReflectionUtils.doWithFields(clazz, new ReflectionUtils.FieldCallback() {
        public void doWith(Field field) {
            for (Class<? extends Annotation> anno : annotations) {
                Annotation annotation = field.getAnnotation(anno);
                if (annotation != null) {
                    if (Modifier.isStatic(field.getModifiers())) {
                        throw new IllegalStateException("Autowired annotation is not supported on static fields");
                    }
                    elements.add(new AutowiredFieldElement(field, annotation));
                }
            }
        }
    });
}
 
Example #8
Source File: AnnotationNacosInjectedBeanPostProcessor.java    From nacos-spring-project with Apache License 2.0 6 votes vote down vote up
@Override
protected String buildInjectedObjectCacheKey(NacosInjected annotation, Object bean,
		String beanName, Class<?> injectedType,
		InjectionMetadata.InjectedElement injectedElement) {

	StringBuilder keyBuilder = new StringBuilder(injectedType.getSimpleName());

	AbstractNacosServiceBeanBuilder serviceBeanBuilder = nacosServiceBeanBuilderMap
			.get(injectedType);

	if (serviceBeanBuilder == null) {
		throw new UnsupportedOperationException(format(
				"Only support to inject types[%s] instance , however actual injected type [%s] in member[%s]",
				nacosServiceBeanBuilderMap.keySet(), injectedType,
				injectedElement.getMember()));
	}

	Properties properties = serviceBeanBuilder
			.resolveProperties(annotation.properties());

	keyBuilder.append(properties);

	return keyBuilder.toString();

}
 
Example #9
Source File: AnnotationInjectedBeanPostProcessor.java    From spring-context-support with Apache License 2.0 6 votes vote down vote up
private InjectionMetadata findInjectionMetadata(String beanName, Class<?> clazz, PropertyValues pvs) {
    // Fall back to class name as cache key, for backwards compatibility with custom callers.
    String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
    // Quick check on the concurrent map first, with minimal locking.
    AnnotatedInjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
    if (InjectionMetadata.needsRefresh(metadata, clazz)) {
        synchronized (this.injectionMetadataCache) {
            metadata = this.injectionMetadataCache.get(cacheKey);
            if (InjectionMetadata.needsRefresh(metadata, clazz)) {
                if (metadata != null) {
                    metadata.clear(pvs);
                }
                try {
                    metadata = buildAnnotatedMetadata(clazz);
                    this.injectionMetadataCache.put(cacheKey, metadata);
                } catch (NoClassDefFoundError err) {
                    throw new IllegalStateException("Failed to introspect object class [" + clazz.getName() +
                            "] for annotation metadata: could not find class that it depends on", err);
                }
            }
        }
    }
    return metadata;
}
 
Example #10
Source File: AbstractAnnotationBeanPostProcessor.java    From spring-context-support with Apache License 2.0 6 votes vote down vote up
/**
 * Get injected-object from specified {@link AnnotationAttributes annotation attributes} and Bean Class
 *
 * @param attributes      {@link AnnotationAttributes the annotation attributes}
 * @param bean            Current bean that will be injected
 * @param beanName        Current bean name that will be injected
 * @param injectedType    the type of injected-object
 * @param injectedElement {@link InjectionMetadata.InjectedElement}
 * @return An injected object
 * @throws Exception If getting is failed
 */
protected Object getInjectedObject(AnnotationAttributes attributes, Object bean, String beanName, Class<?> injectedType,
                                   InjectionMetadata.InjectedElement injectedElement) throws Exception {

    String cacheKey = buildInjectedObjectCacheKey(attributes, bean, beanName, injectedType, injectedElement);

    Object injectedObject = injectedObjectsCache.get(cacheKey);

    if (injectedObject == null) {
        injectedObject = doGetInjectedBean(attributes, bean, beanName, injectedType, injectedElement);
        // Customized inject-object if necessary
        injectedObjectsCache.putIfAbsent(cacheKey, injectedObject);
    }

    return injectedObject;

}
 
Example #11
Source File: CommonAnnotationBeanPostProcessor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private InjectionMetadata findResourceMetadata(String beanName, final Class<?> clazz, PropertyValues pvs) {
	// Fall back to class name as cache key, for backwards compatibility with custom callers.
	String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
	// Quick check on the concurrent map first, with minimal locking.
	InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
	if (InjectionMetadata.needsRefresh(metadata, clazz)) {
		synchronized (this.injectionMetadataCache) {
			metadata = this.injectionMetadataCache.get(cacheKey);
			if (InjectionMetadata.needsRefresh(metadata, clazz)) {
				if (metadata != null) {
					metadata.clear(pvs);
				}
				try {
					metadata = buildResourceMetadata(clazz);
					this.injectionMetadataCache.put(cacheKey, metadata);
				}
				catch (NoClassDefFoundError err) {
					throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName() +
							"] for resource metadata: could not find class that it depends on", err);
				}
			}
		}
	}
	return metadata;
}
 
Example #12
Source File: PersistenceAnnotationBeanPostProcessor.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private InjectionMetadata findPersistenceMetadata(String beanName, final Class<?> clazz, PropertyValues pvs) {
	// Fall back to class name as cache key, for backwards compatibility with custom callers.
	String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
	// Quick check on the concurrent map first, with minimal locking.
	InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
	if (InjectionMetadata.needsRefresh(metadata, clazz)) {
		synchronized (this.injectionMetadataCache) {
			metadata = this.injectionMetadataCache.get(cacheKey);
			if (InjectionMetadata.needsRefresh(metadata, clazz)) {
				if (metadata != null) {
					metadata.clear(pvs);
				}
				try {
					metadata = buildPersistenceMetadata(clazz);
					this.injectionMetadataCache.put(cacheKey, metadata);
				}
				catch (NoClassDefFoundError err) {
					throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName() +
							"] for persistence metadata: could not find class that it depends on", err);
				}
			}
		}
	}
	return metadata;
}
 
Example #13
Source File: InjectAnnotationBeanPostProcessor.java    From spring-boot-starter-dubbo with Apache License 2.0 6 votes vote down vote up
private InjectionMetadata findReferenceMetadata(String beanName, Class<?> clazz, PropertyValues pvs) {
    // Fall back to class name as cache key, for backwards compatibility with custom callers.
    String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
    // Quick check on the concurrent map first, with minimal locking.
    InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
    if (InjectionMetadata.needsRefresh(metadata, clazz)) {
        synchronized (this.injectionMetadataCache) {
            metadata = this.injectionMetadataCache.get(cacheKey);
            if (InjectionMetadata.needsRefresh(metadata, clazz)) {
                if (metadata != null) {
                    metadata.clear(pvs);
                }
                try {
                    metadata = buildReferenceMetadata(clazz);
                    this.injectionMetadataCache.put(cacheKey, metadata);
                } catch (NoClassDefFoundError err) {
                    throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName() +
                            "] for reference metadata: could not find class that it depends on", err);
                }
            }
        }
    }
    return metadata;
}
 
Example #14
Source File: CreateCacheAnnotationBeanPostProcessor.java    From jetcache with Apache License 2.0 6 votes vote down vote up
private InjectionMetadata findAutowiringMetadata(String beanName, Class<?> clazz, PropertyValues pvs) {
    // Fall back to class name as cache key, for backwards compatibility with custom callers.
    String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
    // Quick check on the concurrent map first, with minimal locking.
    InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
    if (InjectionMetadata.needsRefresh(metadata, clazz)) {
        synchronized (this.injectionMetadataCache) {
            metadata = this.injectionMetadataCache.get(cacheKey);
            if (InjectionMetadata.needsRefresh(metadata, clazz)) {
                if (metadata != null) {
                    clear(metadata, pvs);
                }
                try {
                    metadata = buildAutowiringMetadata(clazz);
                    this.injectionMetadataCache.put(cacheKey, metadata);
                } catch (NoClassDefFoundError err) {
                    throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName() +
                            "] for autowiring metadata: could not find class that it depends on", err);
                }
            }
        }
    }
    return metadata;
}
 
Example #15
Source File: CommonAnnotationBeanPostProcessor.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private InjectionMetadata findResourceMetadata(String beanName, final Class<?> clazz, PropertyValues pvs) {
	// Fall back to class name as cache key, for backwards compatibility with custom callers.
	String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
	// Quick check on the concurrent map first, with minimal locking.
	InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
	if (InjectionMetadata.needsRefresh(metadata, clazz)) {
		synchronized (this.injectionMetadataCache) {
			metadata = this.injectionMetadataCache.get(cacheKey);
			if (InjectionMetadata.needsRefresh(metadata, clazz)) {
				if (metadata != null) {
					metadata.clear(pvs);
				}
				try {
					metadata = buildResourceMetadata(clazz);
					this.injectionMetadataCache.put(cacheKey, metadata);
				}
				catch (NoClassDefFoundError err) {
					throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName() +
							"] for resource metadata: could not find class that it depends on", err);
				}
			}
		}
	}
	return metadata;
}
 
Example #16
Source File: AnnotationInjectedBeanPostProcessor.java    From spring-context-support with Apache License 2.0 6 votes vote down vote up
/**
 * Get injected-object from specified {@link A annotation} and Bean Class
 *
 * @param annotation      {@link A annotation}
 * @param bean            Current bean that will be injected
 * @param beanName        Current bean name that will be injected
 * @param injectedType    the type of injected-object
 * @param injectedElement {@link InjectionMetadata.InjectedElement}
 * @return An injected object
 * @throws Exception If getting is failed
 */
protected Object getInjectedObject(A annotation, Object bean, String beanName, Class<?> injectedType,
                                   InjectionMetadata.InjectedElement injectedElement) throws Exception {

    String cacheKey = buildInjectedObjectCacheKey(annotation, bean, beanName, injectedType, injectedElement);

    Object injectedObject = injectedObjectsCache.get(cacheKey);

    if (injectedObject == null) {
        injectedObject = doGetInjectedBean(annotation, bean, beanName, injectedType, injectedElement);
        // Customized inject-object if necessary
        injectedObjectsCache.putIfAbsent(cacheKey, injectedObject);
    }

    return injectedObject;

}
 
Example #17
Source File: PersistenceAnnotationBeanPostProcessor.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private InjectionMetadata findPersistenceMetadata(String beanName, final Class<?> clazz, PropertyValues pvs) {
	// Fall back to class name as cache key, for backwards compatibility with custom callers.
	String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
	// Quick check on the concurrent map first, with minimal locking.
	InjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
	if (InjectionMetadata.needsRefresh(metadata, clazz)) {
		synchronized (this.injectionMetadataCache) {
			metadata = this.injectionMetadataCache.get(cacheKey);
			if (InjectionMetadata.needsRefresh(metadata, clazz)) {
				if (metadata != null) {
					metadata.clear(pvs);
				}
				try {
					metadata = buildPersistenceMetadata(clazz);
					this.injectionMetadataCache.put(cacheKey, metadata);
				}
				catch (NoClassDefFoundError err) {
					throw new IllegalStateException("Failed to introspect bean class [" + clazz.getName() +
							"] for persistence metadata: could not find class that it depends on", err);
				}
			}
		}
	}
	return metadata;
}
 
Example #18
Source File: AbstractAnnotationBeanPostProcessor.java    From spring-context-support with Apache License 2.0 6 votes vote down vote up
private InjectionMetadata findInjectionMetadata(String beanName, Class<?> clazz, PropertyValues pvs) {
    // Fall back to class name as cache key, for backwards compatibility with custom callers.
    String cacheKey = (StringUtils.hasLength(beanName) ? beanName : clazz.getName());
    // Quick check on the concurrent map first, with minimal locking.
    AbstractAnnotationBeanPostProcessor.AnnotatedInjectionMetadata metadata = this.injectionMetadataCache.get(cacheKey);
    if (InjectionMetadata.needsRefresh(metadata, clazz)) {
        synchronized (this.injectionMetadataCache) {
            metadata = this.injectionMetadataCache.get(cacheKey);
            if (InjectionMetadata.needsRefresh(metadata, clazz)) {
                if (metadata != null) {
                    metadata.clear(pvs);
                }
                try {
                    metadata = buildAnnotatedMetadata(clazz);
                    this.injectionMetadataCache.put(cacheKey, metadata);
                } catch (NoClassDefFoundError err) {
                    throw new IllegalStateException("Failed to introspect object class [" + clazz.getName() +
                            "] for annotation metadata: could not find class that it depends on", err);
                }
            }
        }
    }
    return metadata;
}
 
Example #19
Source File: InjectAnnotationBeanPostProcessor.java    From spring-boot-starter-dubbo with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
    if (beanType != null) {
        InjectionMetadata metadata = findReferenceMetadata(beanName, beanType, null);
        metadata.checkConfigMembers(beanDefinition);
    }
}
 
Example #20
Source File: InjectAnnotationBeanPostProcessor.java    From spring-boot-starter-dubbo with Apache License 2.0 5 votes vote down vote up
private List<InjectionMetadata.InjectedElement> findFieldReferenceMetadata(final Class<?> beanClass) {

        final List<InjectionMetadata.InjectedElement> elements = new LinkedList<InjectionMetadata.InjectedElement>();

        ReflectionUtils.doWithFields(beanClass, new ReflectionUtils.FieldCallback() {
            @Override
            public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {

            	Inject inject = findReferenceAnnotation(field);
                if (inject == null) {
                	return;
                }
                if (Modifier.isStatic(field.getModifiers())) {
                    logger.warn("@Reference 静态方法不支持注释: {}" , field);
                    return;
                }
            	Class<?> requiredType = field.getDeclaringClass();
            	Object bean= getBean(inject, requiredType);
                if(bean!=null){
                	elements.add(injectBeanPostProcessor.createAutowiredFieldElement(field, true));
                	return;
                }
                elements.add(new ReferenceFieldElement(field, inject.value()));
             }

        });

        return elements;

    }
 
Example #21
Source File: CommonAnnotationBeanPostProcessor.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
	super.postProcessMergedBeanDefinition(beanDefinition, beanType, beanName);
	if (beanType != null) {
		InjectionMetadata metadata = findResourceMetadata(beanName, beanType, null);
		metadata.checkConfigMembers(beanDefinition);
	}
}
 
Example #22
Source File: PersistenceAnnotationBeanPostProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
	if (beanType != null) {
		InjectionMetadata metadata = findPersistenceMetadata(beanName, beanType, null);
		metadata.checkConfigMembers(beanDefinition);
	}
}
 
Example #23
Source File: CommonAnnotationBeanPostProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PropertyValues postProcessPropertyValues(
		PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {

	InjectionMetadata metadata = findResourceMetadata(beanName, bean.getClass(), pvs);
	try {
		metadata.inject(bean, beanName, pvs);
	}
	catch (Throwable ex) {
		throw new BeanCreationException(beanName, "Injection of resource dependencies failed", ex);
	}
	return pvs;
}
 
Example #24
Source File: CommonAnnotationBeanPostProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
	super.postProcessMergedBeanDefinition(beanDefinition, beanType, beanName);
	if (beanType != null) {
		InjectionMetadata metadata = findResourceMetadata(beanName, beanType, null);
		metadata.checkConfigMembers(beanDefinition);
	}
}
 
Example #25
Source File: PersistenceAnnotationBeanPostProcessor.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public PropertyValues postProcessPropertyValues(
		PropertyValues pvs, PropertyDescriptor[] pds, Object bean, String beanName) throws BeansException {

	InjectionMetadata metadata = findPersistenceMetadata(beanName, bean.getClass(), pvs);
	try {
		metadata.inject(bean, beanName, pvs);
	}
	catch (Throwable ex) {
		throw new BeanCreationException(beanName, "Injection of persistence dependencies failed", ex);
	}
	return pvs;
}
 
Example #26
Source File: AbstractAnnotationBeanPostProcessor.java    From spring-context-support with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
    if (beanType != null) {
        InjectionMetadata metadata = findInjectionMetadata(beanName, beanType, null);
        metadata.checkConfigMembers(beanDefinition);
    }
}
 
Example #27
Source File: ReferenceAnnotationBeanPostProcessor.java    From dubbo-2.6.5 with Apache License 2.0 5 votes vote down vote up
private void cacheInjectedReferenceBean(ReferenceBean referenceBean,
                                        InjectionMetadata.InjectedElement injectedElement) {
    if (injectedElement.getMember() instanceof Field) {
        injectedFieldReferenceBeanCache.put(injectedElement, referenceBean);
    } else if (injectedElement.getMember() instanceof Method) {
        injectedMethodReferenceBeanCache.put(injectedElement, referenceBean);
    }
}
 
Example #28
Source File: CreateCacheAnnotationBeanPostProcessor.java    From jetcache with Apache License 2.0 5 votes vote down vote up
private InjectionMetadata buildAutowiringMetadata(final Class<?> clazz) {
    LinkedList<InjectionMetadata.InjectedElement> elements = new LinkedList<InjectionMetadata.InjectedElement>();
    Class<?> targetClass = clazz;

    do {
        final LinkedList<InjectionMetadata.InjectedElement> currElements =
                new LinkedList<InjectionMetadata.InjectedElement>();

        doWithLocalFields(targetClass, new ReflectionUtils.FieldCallback() {
            @Override
            public void doWith(Field field) throws IllegalArgumentException, IllegalAccessException {
                CreateCache ann = field.getAnnotation(CreateCache.class);
                if (ann != null) {
                    if (Modifier.isStatic(field.getModifiers())) {
                        if (logger.isWarnEnabled()) {
                            logger.warn("Autowired annotation is not supported on static fields: " + field);
                        }
                        return;
                    }
                    currElements.add(new AutowiredFieldElement(field, ann));
                }
            }
        });

        elements.addAll(0, currElements);
        targetClass = targetClass.getSuperclass();
    }
    while (targetClass != null && targetClass != Object.class);

    return new InjectionMetadata(clazz, elements);
}
 
Example #29
Source File: AnnotationInjectedBeanPostProcessor.java    From spring-context-support with Apache License 2.0 5 votes vote down vote up
@Override
public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
    if (beanType != null) {
        InjectionMetadata metadata = findInjectionMetadata(beanName, beanType, null);
        metadata.checkConfigMembers(beanDefinition);
    }
}
 
Example #30
Source File: CommonAnnotationBeanPostProcessor.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) {
	InjectionMetadata metadata = findResourceMetadata(beanName, bean.getClass(), pvs);
	try {
		metadata.inject(bean, beanName, pvs);
	}
	catch (Throwable ex) {
		throw new BeanCreationException(beanName, "Injection of resource dependencies failed", ex);
	}
	return pvs;
}