本文整理汇总了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);
}
示例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;
});
}
示例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;
}
示例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);
}
示例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());
}
示例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());
}
}
示例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());
}
}
}
示例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);
});
}
示例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);
});
}
示例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;
}
示例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;
}
示例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);
}
}