• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java InjectionPoint类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: getConsumerDescription

import org.springframework.beans.factory.InjectionPoint; //导入依赖的package包/类
private String getConsumerDescription(UnsatisfiedDependencyException ex) {
	InjectionPoint injectionPoint = ex.getInjectionPoint();
	if (injectionPoint != null) {
		if (injectionPoint.getField() != null) {
			return String.format("Field %s in %s",
					injectionPoint.getField().getName(),
					injectionPoint.getField().getDeclaringClass().getName());
		}
		if (injectionPoint.getMethodParameter() != null) {
			if (injectionPoint.getMethodParameter().getConstructor() != null) {
				return String.format("Parameter %d of constructor in %s",
						injectionPoint.getMethodParameter().getParameterIndex(),
						injectionPoint.getMethodParameter().getDeclaringClass()
								.getName());
			}
			return String.format("Parameter %d of method %s in %s",
					injectionPoint.getMethodParameter().getParameterIndex(),
					injectionPoint.getMethodParameter().getMethod().getName(),
					injectionPoint.getMethodParameter().getDeclaringClass()
							.getName());
		}
	}
	return ex.getResourceDescription();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:25,代码来源:NoUniqueBeanDefinitionFailureAnalyzer.java


示例2: getDescription

import org.springframework.beans.factory.InjectionPoint; //导入依赖的package包/类
private String getDescription(BeanCreationException ex) {
	if (StringUtils.hasText(ex.getResourceDescription())) {
		return String.format(" defined in %s", ex.getResourceDescription());
	}
	InjectionPoint failedInjectionPoint = findFailedInjectionPoint(ex);
	if (failedInjectionPoint != null && failedInjectionPoint.getField() != null) {
		return String.format(" (field %s)", failedInjectionPoint.getField());
	}
	return "";
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:11,代码来源:BeanCurrentlyInCreationFailureAnalyzer.java


示例3: circuitBreaker

import org.springframework.beans.factory.InjectionPoint; //导入依赖的package包/类
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@ConditionalOnMissingBean(CircuitBreaker.class)
public CircuitBreaker circuitBreaker(final InjectionPoint ip) {
  FailsafeBreaker annotation = null;
  for (final Annotation a : ip.getAnnotations()) {
    if (a instanceof FailsafeBreaker) {
      annotation = (FailsafeBreaker) a;
      break;
    }
  }

  return circuitBreakerRegistry.getOrCreate(annotation.value());
}
 
开发者ID:zalando,项目名称:failsafe-actuator,代码行数:15,代码来源:FailsafeInjectionConfiguration.java


示例4: resolvePreparedArguments

import org.springframework.beans.factory.InjectionPoint; //导入依赖的package包/类
/**
 * Resolve the prepared arguments stored in the given bean definition.
 */
private Object[] resolvePreparedArguments(
		String beanName, RootBeanDefinition mbd, BeanWrapper bw, Member methodOrCtor, Object[] argsToResolve) {

	Class<?>[] paramTypes = (methodOrCtor instanceof Method ?
			((Method) methodOrCtor).getParameterTypes() : ((Constructor<?>) methodOrCtor).getParameterTypes());
	TypeConverter converter = (this.beanFactory.getCustomTypeConverter() != null ?
			this.beanFactory.getCustomTypeConverter() : bw);
	BeanDefinitionValueResolver valueResolver =
			new BeanDefinitionValueResolver(this.beanFactory, beanName, mbd, converter);
	Object[] resolvedArgs = new Object[argsToResolve.length];
	for (int argIndex = 0; argIndex < argsToResolve.length; argIndex++) {
		Object argValue = argsToResolve[argIndex];
		MethodParameter methodParam = MethodParameter.forMethodOrConstructor(methodOrCtor, argIndex);
		GenericTypeResolver.resolveParameterType(methodParam, methodOrCtor.getDeclaringClass());
		if (argValue instanceof AutowiredArgumentMarker) {
			argValue = resolveAutowiredArgument(methodParam, beanName, null, converter);
		}
		else if (argValue instanceof BeanMetadataElement) {
			argValue = valueResolver.resolveValueIfNecessary("constructor argument", argValue);
		}
		else if (argValue instanceof String) {
			argValue = this.beanFactory.evaluateBeanDefinitionString((String) argValue, mbd);
		}
		Class<?> paramType = paramTypes[argIndex];
		try {
			resolvedArgs[argIndex] = converter.convertIfNecessary(argValue, paramType, methodParam);
		}
		catch (TypeMismatchException ex) {
			throw new UnsatisfiedDependencyException(
					mbd.getResourceDescription(), beanName, new InjectionPoint(methodParam),
					"Could not convert argument value of type [" + ObjectUtils.nullSafeClassName(argValue) +
					"] to required type [" + paramType.getName() + "]: " + ex.getMessage());
		}
	}
	return resolvedArgs;
}
 
开发者ID:txazo,项目名称:spring,代码行数:40,代码来源:ConstructorResolver.java


示例5: resolveAutowiredArgument

import org.springframework.beans.factory.InjectionPoint; //导入依赖的package包/类
/**
 * Template method for resolving the specified argument which is supposed to be autowired.
 */
protected Object resolveAutowiredArgument(
		MethodParameter param, String beanName, Set<String> autowiredBeanNames, TypeConverter typeConverter) {

	if (InjectionPoint.class.isAssignableFrom(param.getParameterType())) {
		InjectionPoint injectionPoint = currentInjectionPoint.get();
		if (injectionPoint == null) {
			throw new IllegalStateException("No current InjectionPoint available for " + param);
		}
		return injectionPoint;
	}
	return this.beanFactory.resolveDependency(
			new DependencyDescriptor(param, true), beanName, autowiredBeanNames, typeConverter);
}
 
开发者ID:txazo,项目名称:spring,代码行数:17,代码来源:ConstructorResolver.java


示例6: setCurrentInjectionPoint

import org.springframework.beans.factory.InjectionPoint; //导入依赖的package包/类
static InjectionPoint setCurrentInjectionPoint(InjectionPoint injectionPoint) {
	InjectionPoint old = currentInjectionPoint.get();
	if (injectionPoint != null) {
		currentInjectionPoint.set(injectionPoint);
	}
	else {
		currentInjectionPoint.remove();
	}
	return old;
}
 
开发者ID:txazo,项目名称:spring,代码行数:11,代码来源:ConstructorResolver.java


示例7: logger

import org.springframework.beans.factory.InjectionPoint; //导入依赖的package包/类
@Bean
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
public Logger logger(InjectionPoint ip){
    return LoggerFactory.getLogger(ip.getMember().getDeclaringClass());
}
 
开发者ID:gessnerfl,项目名称:mysql-jdbc-benchmark,代码行数:6,代码来源:LoggerConfig.java


示例8: logger

import org.springframework.beans.factory.InjectionPoint; //导入依赖的package包/类
@Bean
@Scope("prototype")
Logger logger(InjectionPoint ip) {
    return Logger.getLogger(ip.getMember().getDeclaringClass().getName());
}
 
开发者ID:joshlong,项目名称:hintjens-tweets,代码行数:6,代码来源:HintjensApplication.java


示例9: findFailedInjectionPoint

import org.springframework.beans.factory.InjectionPoint; //导入依赖的package包/类
private InjectionPoint findFailedInjectionPoint(BeanCreationException ex) {
	if (!(ex instanceof UnsatisfiedDependencyException)) {
		return null;
	}
	return ((UnsatisfiedDependencyException) ex).getInjectionPoint();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:7,代码来源:BeanCurrentlyInCreationFailureAnalyzer.java


示例10: inject

import org.springframework.beans.factory.InjectionPoint; //导入依赖的package包/类
@Override
protected void inject(Object bean, String beanName, PropertyValues pvs) throws Throwable {
	Field field = (Field) this.member;
	Object value;
	if (this.cached) {
		value = resolvedCachedArgument(beanName, this.cachedFieldValue);
	}
	else {
		DependencyDescriptor desc = new DependencyDescriptor(field, this.required);
		desc.setContainingClass(bean.getClass());
		Set<String> autowiredBeanNames = new LinkedHashSet<String>(1);
		TypeConverter typeConverter = beanFactory.getTypeConverter();
		try {
			value = beanFactory.resolveDependency(desc, beanName, autowiredBeanNames, typeConverter);
		}
		catch (BeansException ex) {
			throw new UnsatisfiedDependencyException(null, beanName, new InjectionPoint(field), ex);
		}
		synchronized (this) {
			if (!this.cached) {
				if (value != null || this.required) {
					this.cachedFieldValue = desc;
					registerDependentBeans(beanName, autowiredBeanNames);
					if (autowiredBeanNames.size() == 1) {
						String autowiredBeanName = autowiredBeanNames.iterator().next();
						if (beanFactory.containsBean(autowiredBeanName)) {
							if (beanFactory.isTypeMatch(autowiredBeanName, field.getType())) {
								this.cachedFieldValue = new RuntimeBeanReference(autowiredBeanName);
							}
						}
					}
				}
				else {
					this.cachedFieldValue = null;
				}
				this.cached = true;
			}
		}
	}
	if (value != null) {
		ReflectionUtils.makeAccessible(field);
		field.set(bean, value);
	}
}
 
开发者ID:txazo,项目名称:spring,代码行数:45,代码来源:AutowiredAnnotationBeanPostProcessor.java


示例11: doResolveDependency

import org.springframework.beans.factory.InjectionPoint; //导入依赖的package包/类
public Object doResolveDependency(DependencyDescriptor descriptor, String beanName,
		Set<String> autowiredBeanNames, TypeConverter typeConverter) throws BeansException {

	Class<?> type = descriptor.getDependencyType();
	Object value = getAutowireCandidateResolver().getSuggestedValue(descriptor);
	if (value != null) {
		if (value instanceof String) {
			String strVal = resolveEmbeddedValue((String) value);
			BeanDefinition bd = (beanName != null && containsBean(beanName) ? getMergedBeanDefinition(beanName) : null);
			value = evaluateBeanDefinitionString(strVal, bd);
		}
		TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter());
		return (descriptor.getField() != null ?
				converter.convertIfNecessary(value, type, descriptor.getField()) :
				converter.convertIfNecessary(value, type, descriptor.getMethodParameter()));
	}

	Object multipleBeans = resolveMultipleBeans(descriptor, beanName, autowiredBeanNames, typeConverter);
	if (multipleBeans != null) {
		return multipleBeans;
	}

	InjectionPoint previousInjectionPoint = ConstructorResolver.setCurrentInjectionPoint(descriptor);
	try {
		Map<String, Object> matchingBeans = findAutowireCandidates(beanName, type, descriptor);
		if (matchingBeans.isEmpty()) {
			if (descriptor.isRequired()) {
				raiseNoSuchBeanDefinitionException(type, descriptor.getResolvableType().toString(), descriptor);
			}
			return null;
		}
		if (matchingBeans.size() > 1) {
			String primaryBeanName = determineAutowireCandidate(matchingBeans, descriptor);
			if (primaryBeanName == null) {
				if (descriptor.isRequired() || !indicatesMultipleBeans(type)) {
					return descriptor.resolveNotUnique(type, matchingBeans);
				}
				else {
					// In case of an optional Collection/Map, silently ignore a non-unique case:
					// possibly it was meant to be an empty collection of multiple regular beans
					// (before 4.3 in particular when we didn't even look for collection beans).
					return null;
				}
			}
			if (autowiredBeanNames != null) {
				autowiredBeanNames.add(primaryBeanName);
			}
			return matchingBeans.get(primaryBeanName);
		}
		// We have exactly one match.
		Map.Entry<String, Object> entry = matchingBeans.entrySet().iterator().next();
		if (autowiredBeanNames != null) {
			autowiredBeanNames.add(entry.getKey());
		}
		return entry.getValue();
	}
	finally {
		ConstructorResolver.setCurrentInjectionPoint(previousInjectionPoint);
	}
}
 
开发者ID:txazo,项目名称:spring,代码行数:61,代码来源:DefaultListableBeanFactory.java


示例12: logger

import org.springframework.beans.factory.InjectionPoint; //导入依赖的package包/类
/**
 * In order to avoid the boiler plate code of logger instantiation in each class we use the InjectionPoint
 * Functionality of stream.
 *
 * We use scope = prototype as a new Logger instance should be created for each Spring Bean
 *
 * @param injectionPoint
 * @return
 */
@Bean
@Scope(value = "prototype")
public Logger logger(InjectionPoint injectionPoint){
    return LoggerFactory.getLogger(injectionPoint.getMember().getDeclaringClass());
}
 
开发者ID:nicolasmanic,项目名称:JRockets,代码行数:15,代码来源:BeanConfig.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java MaterialToast类代码示例发布时间:2022-05-22
下一篇:
Java SessionInterface类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap