当前位置: 首页>>代码示例>>Java>>正文


Java StandardMethodMetadata类代码示例

本文整理汇总了Java中org.springframework.core.type.StandardMethodMetadata的典型用法代码示例。如果您正苦于以下问题:Java StandardMethodMetadata类的具体用法?Java StandardMethodMetadata怎么用?Java StandardMethodMetadata使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


StandardMethodMetadata类属于org.springframework.core.type包,在下文中一共展示了StandardMethodMetadata类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getFactoryMethod

import org.springframework.core.type.StandardMethodMetadata; //导入依赖的package包/类
private Method getFactoryMethod(ConfigurableListableBeanFactory beanFactory,
		BeanDefinition definition) throws Exception {
	if (definition instanceof AnnotatedBeanDefinition) {
		MethodMetadata factoryMethodMetadata = ((AnnotatedBeanDefinition) definition)
				.getFactoryMethodMetadata();
		if (factoryMethodMetadata instanceof StandardMethodMetadata) {
			return ((StandardMethodMetadata) factoryMethodMetadata)
					.getIntrospectedMethod();
		}
	}
	BeanDefinition factoryDefinition = beanFactory
			.getBeanDefinition(definition.getFactoryBeanName());
	Class<?> factoryClass = ClassUtils.forName(factoryDefinition.getBeanClassName(),
			beanFactory.getBeanClassLoader());
	return getFactoryMethod(definition, factoryClass);
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:17,代码来源:BeanTypeRegistry.java

示例2: getBeanNamesByTypeWithAnnotation

import org.springframework.core.type.StandardMethodMetadata; //导入依赖的package包/类
private <T> Stream<String> getBeanNamesByTypeWithAnnotation(Class<? extends Annotation> annotationType, Class<T> beanType) throws Exception {

        return Stream.of(applicationContext.getBeanNamesForType(beanType))
                .filter(name -> {
                    final BeanDefinition beanDefinition = applicationContext.getBeanFactory().getBeanDefinition(name);
                    final Map<String, Object> beansWithAnnotation = applicationContext.getBeansWithAnnotation(annotationType);

                    if (!beansWithAnnotation.isEmpty()) {
                        return beansWithAnnotation.containsKey(name);
                    } else if (beanDefinition.getSource() instanceof StandardMethodMetadata) {
                        StandardMethodMetadata metadata = (StandardMethodMetadata) beanDefinition.getSource();
                        return metadata.isAnnotated(annotationType.getName());
                    }

                    return false;
                });
    }
 
开发者ID:LogNet,项目名称:grpc-spring-boot-starter,代码行数:18,代码来源:GRpcServerRunner.java

示例3: getFactoryMethod

import org.springframework.core.type.StandardMethodMetadata; //导入依赖的package包/类
private Method getFactoryMethod(ConfigurableListableBeanFactory beanFactory,
		BeanDefinition definition) throws Exception {
	if (definition instanceof AnnotatedBeanDefinition) {
		MethodMetadata factoryMethodMetadata = ((AnnotatedBeanDefinition) definition)
				.getFactoryMethodMetadata();
		if (factoryMethodMetadata instanceof StandardMethodMetadata) {
			return ((StandardMethodMetadata) factoryMethodMetadata)
					.getIntrospectedMethod();
		}
	}
	BeanDefinition factoryDefinition = beanFactory
			.getBeanDefinition(definition.getFactoryBeanName());
	Class<?> factoryClass = ClassUtils.forName(factoryDefinition.getBeanClassName(),
			beanFactory.getBeanClassLoader());
	return ReflectionUtils.findMethod(factoryClass,
			definition.getFactoryMethodName());
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:BeanTypeRegistry.java

示例4: getBeansWithAnnotation

import org.springframework.core.type.StandardMethodMetadata; //导入依赖的package包/类
public Map<String, Map<String, Object>> getBeansWithAnnotation(Class<? extends Annotation> type,
                                                               Predicate<Map<String, Object>> attributeFilter) {
	Map<String, Map<String, Object>> result = Maps.newConcurrentMap();
	ConfigurableListableBeanFactory factory = (ConfigurableListableBeanFactory)
			applicationContext.getAutowireCapableBeanFactory();
	for (String name : factory.getBeanDefinitionNames()) {
		BeanDefinition bd = factory.getBeanDefinition(name);
		if (bd.getSource() instanceof StandardMethodMetadata) {
			StandardMethodMetadata metadata = (StandardMethodMetadata) bd.getSource();
			Map<String, Object> attributes = metadata.getAnnotationAttributes(type.getName());
			if (null == attributes) {
				continue;
			}
			if (attributeFilter == null || attributeFilter.apply(attributes)) {
				result.put(name, attributes);
			}
		}
	}
	return result;
}
 
开发者ID:jeffsegal,项目名称:mongo-rest,代码行数:21,代码来源:ClasspathAndBeanScanner.java

示例5: qualifierAttributesFor

import org.springframework.core.type.StandardMethodMetadata; //导入依赖的package包/类
static Map<Class<? extends Annotation>,AnnotationAttributes> qualifierAttributesFor(final MethodMetadata metadata) {
  if (metadata instanceof StandardMethodMetadata) {
    return qualifierFor(metadata, ((StandardMethodMetadata)metadata).getIntrospectedMethod());
  } else {
    if (logger.isDebugEnabled()) {
      logger.debug(String
          .format("Found unsupported method meta data %s for method %s.%s", metadata.getClass(), metadata.getDeclaringClassName(),metadata.getMethodName()));
    }
    try {
  	// TODO find better way to load the specified @Bean method (ignore parameter etc.)
      return qualifierFor(metadata, ReflectionUtils.findMethod(Class.forName(metadata.getDeclaringClassName()), metadata.getMethodName(), null));
    } catch (final ClassNotFoundException e) {
      logger.warn(String
          .format("Cant scan method meta data %s for method %s.%s", metadata.getClass(), metadata.getDeclaringClassName(),metadata.getMethodName()), e);
    }
  }
  return new HashMap<Class<? extends Annotation>, AnnotationAttributes>();
}
 
开发者ID:ahoehma,项目名称:spring-autowire-qualified-beans,代码行数:19,代码来源:ConfigurationClassBeanDefinitionReader.java

示例6: getFactoryMethod

import org.springframework.core.type.StandardMethodMetadata; //导入依赖的package包/类
private Method getFactoryMethod(ConfigurableListableBeanFactory beanFactory,
                                BeanDefinition definition) throws Exception {
    if (definition instanceof AnnotatedBeanDefinition) {
        MethodMetadata factoryMethodMetadata = ((AnnotatedBeanDefinition) definition).getFactoryMethodMetadata();
        if (factoryMethodMetadata instanceof StandardMethodMetadata) {
            return ((StandardMethodMetadata) factoryMethodMetadata).getIntrospectedMethod();
        }
    }
    BeanDefinition factoryDefinition = beanFactory.getBeanDefinition(definition.getFactoryBeanName());
    Class<?> factoryClass = ClassUtils.forName(factoryDefinition.getBeanClassName(), beanFactory.getBeanClassLoader());
    return getFactoryMethod(definition, factoryClass);
}
 
开发者ID:drtrang,项目名称:spring-boot-autoconfigure,代码行数:13,代码来源:BeanTypeRegistry.java

示例7: getTypedBeansWithAnnotation

import org.springframework.core.type.StandardMethodMetadata; //导入依赖的package包/类
private Collection<Object> getTypedBeansWithAnnotation(Class<? extends Annotation> annotationType)
    throws Exception {
  return Stream.of(applicationContext.getBeanNamesForAnnotation(annotationType)).filter(name -> {
    BeanDefinition beanDefinition = applicationContext.getBeanFactory().getBeanDefinition(name);
    if (beanDefinition.getSource() instanceof StandardMethodMetadata) {
      StandardMethodMetadata metadata = (StandardMethodMetadata) beanDefinition.getSource();
      return metadata.isAnnotated(annotationType.getName());
    }
    return null != applicationContext.getBeanFactory().findAnnotationOnBean(name, annotationType);
  }).map(name -> applicationContext.getBeanFactory().getBean(name)).collect(Collectors.toList());

}
 
开发者ID:venus-boot,项目名称:saluki,代码行数:13,代码来源:GrpcServiceRunner.java

示例8: startServer

import org.springframework.core.type.StandardMethodMetadata; //导入依赖的package包/类
public void startServer() {

        preHandle();

        ServerBuilder serverBuilder = ServerBuilder.forPort(grpcServerProperties.getPort());

        Stream.of(applicationContext.getBeanNamesForType(BindableService.class)).filter(name->{
            final BeanDefinition beanDefinition = applicationContext.getBeanFactory().getBeanDefinition(name);
            final Map<String, Object> beansWithAnnotation = applicationContext.getBeansWithAnnotation(GrpcService.class);

            if ( !beansWithAnnotation.isEmpty() ) {
                return beansWithAnnotation.containsKey(name);
            } else if( beanDefinition.getSource() instanceof StandardMethodMetadata) {
                StandardMethodMetadata metadata = (StandardMethodMetadata) beanDefinition.getSource();
                return metadata.isAnnotated(GrpcService.class.getName());
            }
            return false;
        }).forEach(name->{
            BindableService srv = applicationContext.getBeanFactory().getBean(name, BindableService.class);
            ServerServiceDefinition serviceDefinition = srv.bindService();
            serverBuilder.addService(ServerInterceptors.intercept(serviceDefinition,getInterceptors()));
			logger.info("GRPC Service add {}",name);
        });

        try {
            server = serverBuilder.build().start();
            logger.info("GRPC Server started at port{}",grpcServerProperties.getPort());
            startAwait();
        } catch (IOException e) {
            logger.info(e.getMessage(),e);
            throw new MSGrpcException("grpc start error:" + e.getMessage());
        }
    }
 
开发者ID:moensun,项目名称:ms-grpc,代码行数:34,代码来源:GrpcServer.java

示例9: processAnnotationOnMethod

import org.springframework.core.type.StandardMethodMetadata; //导入依赖的package包/类
private void processAnnotationOnMethod(Method method, MethodMetadata.Builder requestTemplateBuilder) {
    AnnotatedTypeMetadata methodMetadata = new StandardMethodMetadata(method);
    Parameter[] parameters = method.getParameters();

    processRequestMappingAnnotation(methodMetadata, requestTemplateBuilder);

    for (int i = 0; i < parameters.length; i++) {
        Parameter parameter = parameters[i];
        processAnnotationsOnParameter(requestTemplateBuilder, parameter, i);
        if (parameter.getAnnotations().length == 0) {
            requestTemplateBuilder.body(i, parameter.getParameterizedType());
        }
    }
}
 
开发者ID:jbrixhe,项目名称:spring-webflux-client,代码行数:15,代码来源:MethodMetadataFactory.java

示例10: getBeanNamesByTypeWithAnnotation

import org.springframework.core.type.StandardMethodMetadata; //导入依赖的package包/类
private <T> Stream<String> getBeanNamesByTypeWithAnnotation(Class<? extends Annotation> annotationType, Class<T> beanType) throws Exception {
    return Stream.of(applicationContext.getBeanNamesForType(beanType))
            .filter(name -> {
                BeanDefinition beanDefinition = applicationContext.getBeanFactory().getBeanDefinition(name);
                if (beanDefinition.getSource() instanceof StandardMethodMetadata) {
                    StandardMethodMetadata metadata = (StandardMethodMetadata) beanDefinition.getSource();
                    return metadata.isAnnotated(annotationType.getName());
                }
                return null != applicationContext.getBeanFactory().findAnnotationOnBean(name, annotationType);
            });
}
 
开发者ID:Wangzr,项目名称:micro-service-framework,代码行数:12,代码来源:GRpcServerRunner.java

示例11: getBeanNamesByTypeWithAnnotation

import org.springframework.core.type.StandardMethodMetadata; //导入依赖的package包/类
private <T> Stream<String> getBeanNamesByTypeWithAnnotation(Class<? extends Annotation> annotationType, Class<T> beanType) {

    return Stream.of(SpringContainer.getContext().getBeanNamesForType(beanType))
             .filter(name->{
                 BeanDefinition beanDefinition = SpringContainer.getContext().getBeanFactory().getBeanDefinition(name);
                 if( beanDefinition.getSource() instanceof StandardMethodMetadata) {
                     StandardMethodMetadata metadata = (StandardMethodMetadata) beanDefinition.getSource();
                     return metadata.isAnnotated(annotationType.getName());
                 }
                 return null!= SpringContainer.getContext().getBeanFactory().findAnnotationOnBean(name, annotationType);
             });
 }
 
开发者ID:benson-git,项目名称:ibole-microservice,代码行数:13,代码来源:SpringBeanServiceDefinitionLoader.java

示例12: getQualifier

import org.springframework.core.type.StandardMethodMetadata; //导入依赖的package包/类
private String getQualifier(String key) {
	if (registry != null && registry.containsBeanDefinition(key)) {
		BeanDefinition beanDefinition = registry.getBeanDefinition(key);
		Object source = beanDefinition.getSource();
		if (source instanceof StandardMethodMetadata) {
			StandardMethodMetadata metadata = (StandardMethodMetadata) source;
			Qualifier qualifier = AnnotatedElementUtils.findMergedAnnotation(
					metadata.getIntrospectedMethod(), Qualifier.class);
			if (qualifier != null && qualifier.value().length() > 0) {
				return qualifier.value();
			}
		}
	}
	return key;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-function,代码行数:16,代码来源:ContextFunctionCatalogAutoConfiguration.java

示例13: getClassFromMethodMetadata

import org.springframework.core.type.StandardMethodMetadata; //导入依赖的package包/类
/**
 * Case when the Bean is being declared in a @Configuration, and we cannot
 * get the BeanClassName directly from the BeanDefinition.
 * <p>
 * In this case we need to get the class from the IntrospectedMethod in the
 * beanDefinition "source"
 * 
 * @param beanDefinition
 * @return
 */
private Class<?> getClassFromMethodMetadata(final BeanDefinition beanDefinition) {
	final Object source = beanDefinition.getSource();
	if (source != null && StandardMethodMetadata.class.isInstance(source)) {
		final StandardMethodMetadata methodMetadata = StandardMethodMetadata.class.cast(source);
		final Method introspectedMethod = methodMetadata.getIntrospectedMethod();
		if (introspectedMethod != null) {
			return introspectedMethod.getReturnType();
		}
	}
	return null;
}
 
开发者ID:rinoto,项目名称:spring-auto-mock,代码行数:22,代码来源:AutoMockRegistryPostProcessor.java

示例14: getBeanClass

import org.springframework.core.type.StandardMethodMetadata; //导入依赖的package包/类
/**
 * Try to obtain the actual bean class of the bean with given name.
 * @param beanName Bean name
 * @param beanDefinition Optional bean definition
 * @param beanFactory Bean factory (not null)
 * @param classLoader ClassLoader to use
 * @return The bean class, or <code>null</code> if cannot be detected
 */
public static Class<?> getBeanClass(String beanName, BeanDefinition beanDefinition,
		ConfigurableListableBeanFactory beanFactory, ClassLoader classLoader) {

	ObjectUtils.argumentNotNull(beanFactory, "Bean factory must be not null");

	BeanDefinition definition = beanDefinition;
	if (definition == null && beanName != null) {
		definition = beanFactory.getBeanDefinition(beanName);
	}

	if (definition == null) {
		throw new BeanDefinitionValidationException("Missing bean definition for bean name [" + beanName + "]");
	}

	// check Root definition
	if (definition instanceof RootBeanDefinition) {
		RootBeanDefinition rootBeanDef = (RootBeanDefinition) definition;
		try {
			if (rootBeanDef.getBeanClass() != null) {
				return rootBeanDef.getBeanClass();
			}
		} catch (@SuppressWarnings("unused") IllegalStateException e) {
			// factory bean: ignore
		}
	}

	// Check factory bean
	if (definition.getFactoryMethodName() == null) {
		// factory class
		if (definition.getBeanClassName() != null) {
			return getBeanClass(beanName, definition.getBeanClassName(), classLoader);
		}
	} else {
		// factory method
		String factoryClassName = getBeanFactoryClassName(definition, beanFactory);
		if (factoryClassName != null) {
			Class<?> factoryClass = getBeanClass(beanName, factoryClassName, classLoader);
			if (factoryClass != null) {
				for (Method method : factoryClass.getMethods()) {
					if (method.getName().equals(definition.getFactoryMethodName())) {
						return method.getReturnType();
					}
				}
			}
		}
	}

	// check beans defined using @Configuration
	Object source = definition.getSource();
	if (source instanceof StandardMethodMetadata) {
		StandardMethodMetadata metadata = (StandardMethodMetadata) source;
		return metadata.getIntrospectedMethod().getReturnType();
	}

	return null;

}
 
开发者ID:holon-platform,项目名称:holon-core,代码行数:66,代码来源:BeanRegistryUtils.java

示例15: registerBeanDefinition

import org.springframework.core.type.StandardMethodMetadata; //导入依赖的package包/类
@Override
public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) {
    try {
        Class<?> beanClazz = null;
        String beanClassName = beanDefinition.getBeanClassName();

        // Fix for @Bean annotations in @Configuration will return a "null" beanClassName. This
        // finds the class anyway:
        if (beanClassName == null && beanDefinition instanceof AnnotatedBeanDefinition) {
            MethodMetadata factoryMethodMetadata =
                    ((AnnotatedBeanDefinition) beanDefinition).getFactoryMethodMetadata();
            if (factoryMethodMetadata instanceof StandardMethodMetadata) {
                StandardMethodMetadata methodMetaData = (StandardMethodMetadata) factoryMethodMetadata;
                beanClazz = methodMetaData.getIntrospectedMethod().getReturnType();
            } else {
                // Try to find the method directly from the defining class/method
                String declaringClassName = factoryMethodMetadata.getDeclaringClassName();
                Class<?> factoryClazz = Class.forName(declaringClassName);

                // Note that MethodMetadata does not give us the exact method, we have to loop through to find
                // one which matches the name -- this is not optimal. But it should not matter much, the only thing
                // which may trip this up is having two classes with same name but different return values which is
                // not something we would expect in (sane) @Configuration classes.
                for (Method m : factoryClazz.getDeclaredMethods()) {
                    if (factoryMethodMetadata.getMethodName().equals(m.getName())) {
                        beanClazz = m.getReturnType();
                    }
                }
            }
        }

        if (beanClassName != null) {
            beanClazz = Class.forName(beanClassName);
        }
        if (beanClazz != null && isBeanRejected(beanName, beanClazz)) {
            log.info("Rejected bean [{}] with definiton [{}]", beanName, beanDefinition);
        } else {
            if (beanClazz == null) {
                log.warn("Unable to find beanclass for bean [{}] with definition [{}]", beanName, beanDefinition);
            }
            if (remockConfig.getEagerBeanClasses().contains(beanClazz)
                    || remockConfig.getEagerBeanNames().contains(beanName)) {
                beanDefinition.setLazyInit(false);
            } else if (!remockConfig.disableLazyInit()) {
                beanDefinition.setLazyInit(true);
            }
            super.registerBeanDefinition(beanName, beanDefinition);
        }
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:ksaua,项目名称:remock,代码行数:53,代码来源:RemockBeanFactory.java


注:本文中的org.springframework.core.type.StandardMethodMetadata类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。