本文整理汇总了Java中org.springframework.util.ReflectionUtils.doWithMethods方法的典型用法代码示例。如果您正苦于以下问题:Java ReflectionUtils.doWithMethods方法的具体用法?Java ReflectionUtils.doWithMethods怎么用?Java ReflectionUtils.doWithMethods使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.util.ReflectionUtils
的用法示例。
在下文中一共展示了ReflectionUtils.doWithMethods方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: afterPropertiesSet
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Override
public void afterPropertiesSet() throws Exception {
String[] beanNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this.applicationContext, Object.class);
for(String beanName : beanNames){
Class<?> beanType = this.applicationContext.getType(beanName);
if(beanType != null){
final Class<?> userType = ClassUtils.getUserClass(beanType);
ReflectionUtils.doWithMethods(userType, method -> {
if(AnnotatedElementUtils.findMergedAnnotation(method, ReactiveSocket.class) != null) {
ServiceMethodInfo info = new ServiceMethodInfo(method);
logger.info("Registering remote endpoint at path {}, exchange {} for method {}", info.getMappingInfo().getPath(), info.getMappingInfo().getExchangeMode(), method);
MethodHandler methodHandler = new MethodHandler(applicationContext.getBean(beanName), info);
mappingHandlers.add(methodHandler);
}
});
}
}
initDefaultConverters();
}
示例2: findFactoryMethod
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private Method findFactoryMethod(String beanName) {
if (!this.beans.containsKey(beanName)) {
return null;
}
final AtomicReference<Method> found = new AtomicReference<Method>(null);
MetaData meta = this.beans.get(beanName);
final String factory = meta.getMethod();
Class<?> type = this.beanFactory.getType(meta.getBean());
ReflectionUtils.doWithMethods(type, new MethodCallback() {
@Override
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
if (method.getName().equals(factory)) {
found.compareAndSet(null, method);
}
}
});
return found.get();
}
示例3: injectServicesViaAnnotatedSetterMethods
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private void injectServicesViaAnnotatedSetterMethods(final Object bean, final String beanName) {
ReflectionUtils.doWithMethods(bean.getClass(), new ReflectionUtils.MethodCallback() {
public void doWith(Method method) {
ServiceReference s = AnnotationUtils.getAnnotation(method, ServiceReference.class);
if (s != null && method.getParameterTypes().length == 1) {
try {
if (logger.isDebugEnabled())
logger.debug("Processing annotation [" + s + "] for [" + bean.getClass().getName() + "."
+ method.getName() + "()] on bean [" + beanName + "]");
method.invoke(bean, getServiceImporter(s, method, beanName).getObject());
}
catch (Exception e) {
throw new IllegalArgumentException("Error processing service annotation", e);
}
}
}
});
}
示例4: selectMethods
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
* Select handler methods for the given handler type.
* <p>Callers define handler methods of interest through the {@link MethodFilter} parameter.
* @param handlerType the handler type to search handler methods on
* @param handlerMethodFilter a {@link MethodFilter} to help recognize handler methods of interest
* @return the selected methods, or an empty set
*/
public static Set<Method> selectMethods(final Class<?> handlerType, final MethodFilter handlerMethodFilter) {
final Set<Method> handlerMethods = new LinkedHashSet<Method>();
Set<Class<?>> handlerTypes = new LinkedHashSet<Class<?>>();
Class<?> specificHandlerType = null;
if (!Proxy.isProxyClass(handlerType)) {
handlerTypes.add(handlerType);
specificHandlerType = handlerType;
}
handlerTypes.addAll(Arrays.asList(handlerType.getInterfaces()));
for (Class<?> currentHandlerType : handlerTypes) {
final Class<?> targetClass = (specificHandlerType != null ? specificHandlerType : currentHandlerType);
ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() {
@Override
public void doWith(Method method) {
Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
if (handlerMethodFilter.matches(specificMethod) &&
(bridgedMethod == specificMethod || !handlerMethodFilter.matches(bridgedMethod))) {
handlerMethods.add(specificMethod);
}
}
}, ReflectionUtils.USER_DECLARED_METHODS);
}
return handlerMethods;
}
示例5: addCacheExpires
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private void addCacheExpires(final Class clazz, final Map<String, Long> cacheExpires) {
ReflectionUtils.doWithMethods(clazz, method -> {
ReflectionUtils.makeAccessible(method);
CacheDuration cacheDuration = findCacheDuration(clazz, method);
Cacheable cacheable = findAnnotation(method, Cacheable.class);
CacheConfig cacheConfig = findAnnotation(clazz, CacheConfig.class);
Set<String> cacheNames = findCacheNames(cacheConfig, cacheable);
for (String cacheName : cacheNames) {
if (cacheDuration != null) {
cacheExpires.put(cacheName, cacheDuration.expireSeconds());
}
}
}, method -> null != findAnnotation(method, Cacheable.class));
}
示例6: postProcessAfterInitialization
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Override
public Object postProcessAfterInitialization(final Object bean, String beanName) {
Class<?> targetClass = AopUtils.getTargetClass(bean);
ReflectionUtils.doWithMethods(targetClass, new MethodCallback() {
@Override
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
for (Scheduled scheduled : AnnotationUtils.getRepeatableAnnotation(method, Schedules.class, Scheduled.class)) {
processScheduled(scheduled, method, bean);
}
}
});
return bean;
}
示例7: init
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
* Initialize a new HandlerMethodResolver for the specified handler type.
* @param handlerType the handler class to introspect
*/
public void init(final Class<?> handlerType) {
Set<Class<?>> handlerTypes = new LinkedHashSet<Class<?>>();
Class<?> specificHandlerType = null;
if (!Proxy.isProxyClass(handlerType)) {
handlerTypes.add(handlerType);
specificHandlerType = handlerType;
}
handlerTypes.addAll(Arrays.asList(handlerType.getInterfaces()));
for (Class<?> currentHandlerType : handlerTypes) {
final Class<?> targetClass = (specificHandlerType != null ? specificHandlerType : currentHandlerType);
ReflectionUtils.doWithMethods(currentHandlerType, new ReflectionUtils.MethodCallback() {
@Override
public void doWith(Method method) {
Method specificMethod = ClassUtils.getMostSpecificMethod(method, targetClass);
Method bridgedMethod = BridgeMethodResolver.findBridgedMethod(specificMethod);
if (isHandlerMethod(specificMethod) &&
(bridgedMethod == specificMethod || !isHandlerMethod(bridgedMethod))) {
handlerMethods.add(specificMethod);
}
else if (isInitBinderMethod(specificMethod) &&
(bridgedMethod == specificMethod || !isInitBinderMethod(bridgedMethod))) {
initBinderMethods.add(specificMethod);
}
else if (isModelAttributeMethod(specificMethod) &&
(bridgedMethod == specificMethod || !isModelAttributeMethod(bridgedMethod))) {
modelAttributeMethods.add(specificMethod);
}
}
}, ReflectionUtils.USER_DECLARED_METHODS);
}
this.typeLevelMapping = AnnotationUtils.findAnnotation(handlerType, RequestMapping.class);
SessionAttributes sessionAttributes = AnnotationUtils.findAnnotation(handlerType, SessionAttributes.class);
this.sessionAttributesFound = (sessionAttributes != null);
if (this.sessionAttributesFound) {
this.sessionAttributeNames.addAll(Arrays.asList(sessionAttributes.value()));
this.sessionAttributeTypes.addAll(Arrays.asList(sessionAttributes.types()));
}
}
示例8: getAdvisorMethods
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private List<Method> getAdvisorMethods(Class<?> aspectClass) {
final List<Method> methods = new LinkedList<Method>();
ReflectionUtils.doWithMethods(aspectClass, new ReflectionUtils.MethodCallback() {
@Override
public void doWith(Method method) throws IllegalArgumentException {
// Exclude pointcuts
if (AnnotationUtils.getAnnotation(method, Pointcut.class) == null) {
methods.add(method);
}
}
});
Collections.sort(methods, METHOD_COMPARATOR);
return methods;
}
示例9: postProcessBeforeInitialization
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
Class<?> targetClass = AopUtils.getTargetClass(bean);
ReflectionUtils.doWithMethods(targetClass, method -> {
WxButton wxButton = AnnotationUtils.getAnnotation(method, WxButton.class);
if (wxButton != null) {
wxMenuManager.add(wxButton);
}
});
return bean;
}
示例10: checkMethod
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private void checkMethod(Object bean) {
ReflectionUtils.doWithMethods(
bean.getClass(),
new CompensableMethodCheckingCallback(bean, compensationContext));
}
示例11: getClassServiceDependencies
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private Set<OsgiServiceDependency> getClassServiceDependencies(final Class<?> beanClass, final String beanName,
final BeanDefinition definition) {
final Set<OsgiServiceDependency> dependencies = new LinkedHashSet<OsgiServiceDependency>();
ReflectionUtils.doWithMethods(beanClass, new ReflectionUtils.MethodCallback() {
public void doWith(final Method method) {
final ServiceReference s = AnnotationUtils.getAnnotation(method, ServiceReference.class);
if (s != null && method.getParameterTypes().length == 1
&& !Collection.class.isAssignableFrom(method.getParameterTypes()[0])
// Ignore definitions overridden in the XML config
&& !definition.getPropertyValues().contains(getPropertyName(method))) {
try {
if (logger.isDebugEnabled())
logger.debug("Processing annotation [" + s + "] for [" + beanClass.getName() + "."
+ method.getName() + "()] on bean [" + beanName + "]");
dependencies.add(new OsgiServiceDependency() {
public Filter getServiceFilter() {
return getUnifiedFilter(s, method, beanName);
}
public boolean isMandatory() {
return s.cardinality() == Availability.MANDATORY;
}
public String getBeanName() {
return beanName;
}
public String toString() {
return beanName + "." + method.getName() + ": " + getServiceFilter()
+ (isMandatory() ? " (mandatory)" : " (optional)");
}
});
}
catch (Exception e) {
throw new IllegalArgumentException("Error processing service annotation", e);
}
}
}
});
return dependencies;
}
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:44,代码来源:ServiceReferenceDependencyBeanFactoryPostProcessor.java
示例12: getTypeForFactoryBean
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
/**
* This implementation attempts to query the FactoryBean's generic parameter metadata
* if present to determine the object type. If not present, i.e. the FactoryBean is
* declared as a raw type, checks the FactoryBean's {@code getObjectType} method
* on a plain instance of the FactoryBean, without bean properties applied yet.
* If this doesn't return a type yet, a full creation of the FactoryBean is
* used as fallback (through delegation to the superclass's implementation).
* <p>The shortcut check for a FactoryBean is only applied in case of a singleton
* FactoryBean. If the FactoryBean instance itself is not kept as singleton,
* it will be fully created to check the type of its exposed object.
*/
@Override
protected Class<?> getTypeForFactoryBean(String beanName, RootBeanDefinition mbd) {
class Holder { Class<?> value = null; }
final Holder objectType = new Holder();
String factoryBeanName = mbd.getFactoryBeanName();
final String factoryMethodName = mbd.getFactoryMethodName();
if (factoryBeanName != null) {
if (factoryMethodName != null) {
// Try to obtain the FactoryBean's object type without instantiating it at all.
BeanDefinition fbDef = getBeanDefinition(factoryBeanName);
if (fbDef instanceof AbstractBeanDefinition && ((AbstractBeanDefinition) fbDef).hasBeanClass()) {
// CGLIB subclass methods hide generic parameters; look at the original user class.
Class<?> fbClass = ClassUtils.getUserClass(((AbstractBeanDefinition) fbDef).getBeanClass());
// Find the given factory method, taking into account that in the case of
// @Bean methods, there may be parameters present.
ReflectionUtils.doWithMethods(fbClass,
new ReflectionUtils.MethodCallback() {
@Override
public void doWith(Method method) throws IllegalArgumentException, IllegalAccessException {
if (method.getName().equals(factoryMethodName) &&
FactoryBean.class.isAssignableFrom(method.getReturnType())) {
objectType.value = GenericTypeResolver.resolveReturnTypeArgument(method, FactoryBean.class);
}
}
});
if (objectType.value != null) {
return objectType.value;
}
}
}
// If not resolvable above and the referenced factory bean doesn't exist yet,
// exit here - we don't want to force the creation of another bean just to
// obtain a FactoryBean's object type...
if (!isBeanEligibleForMetadataCaching(factoryBeanName)) {
return null;
}
}
FactoryBean<?> fb = (mbd.isSingleton() ?
getSingletonFactoryBeanForTypeCheck(beanName, mbd) :
getNonSingletonFactoryBeanForTypeCheck(beanName, mbd));
if (fb != null) {
// Try to obtain the FactoryBean's object type from this early stage of the instance.
objectType.value = getTypeForFactoryBean(fb);
if (objectType.value != null) {
return objectType.value;
}
}
// No type found - fall back to full creation of the FactoryBean instance.
return super.getTypeForFactoryBean(beanName, mbd);
}
示例13: processStepsBean
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
private void processStepsBean(String beanName, Class wrapped) {
checkState(context.isSingleton(beanName), "Beans annotated @Steps must have singleton scope.");
for (ReflectionUtils.MethodCallback callback : callbacks) {
ReflectionUtils.doWithMethods(wrapped, callback);
}
}
示例14: postProcessAfterInitialization
import org.springframework.util.ReflectionUtils; //导入方法依赖的package包/类
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
ProxyCreatingMethodCallback callback = new ProxyCreatingMethodCallback(store, bean);
ReflectionUtils.doWithMethods(bean.getClass(), callback);
return callback.getBean() == null ? bean : callback.getBean();
}
开发者ID:olivergierke,项目名称:spring-domain-events,代码行数:11,代码来源:CompletionRegisteringBeanPostProcessor.java