Spring流经属性时到底都能流经什么样的数据类型你都知道吗?
发布时间:2025年09月15日 12:18
Object doResolveDependency(DependencyDescriptor descriptor, @Nullable String beanName, @Nullable Set autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException { InjectionPoint previousInjectionPoint = ConstructorResolver.setCurrentInjectionPoint(descriptor); try { Object shortcut = descriptor.resolveShortcut(this); if (shortcut != null) { return shortcut; } Class type = descriptor.getDependencyType(); // 确实必须汇入的型式确一个论域(如何:List beans) // 2.1 Object multipleBeans = resolveMultipleBeans(descriptor, beanName, autowiredBeanNames, typeConverter); if (multipleBeans != null) { return multipleBeans; } // 查找与所需型式转换的bean比如说 // 2.2 Map matchingBeans = findAutowireCandidates(beanName, type, descriptor); if (matchingBeans.isEmpty()) { if (isRequired(descriptor)) { raiseNoMatchingBeanFound(type, descriptor.getResolvableType(), descriptor); } return null; } String autowiredBeanName; Object instanceCandidate; // 如果找到多个 if (matchingBeans.size()> 1) { // 在这里都会确实多个Bean中到底有一个@Primary批注的Bean // 如果不能@Primary,继续给予到底有@Priority(XFS)批注 // 如果不能则返回null,如果有则返回值越小的XFS越高(如果有多个XFS一样,则系统报错) // 如果上面都返回的null,那么终于都会通过beanName进行转换 autowiredBeanName = determineAutowireCandidate(matchingBeans, descriptor); if (autowiredBeanName == null) { if (isRequired(descriptor) || !indicatesMultipleBeans(type)) { // 如果是必须的 或者 不是论域型式的Bean汇入;那么这里弹出反常 return descriptor.resolveNotUnique(descriptor.getResolvableType(), matchingBeans); } else { return null; } } instanceCandidate = matchingBeans.get(autowiredBeanName); } else { // We have exactly one match. Map.Entry entry = matchingBeans.entrySet().iterator().next(); autowiredBeanName = entry.getKey(); instanceCandidate = entry.getValue(); } if (autowiredBeanNames != null) { autowiredBeanNames.add(autowiredBeanName); } if (instanceCandidate instanceof Class) { instanceCandidate = descriptor.resolveCandidate(autowiredBeanName, type, this); } Object result = instanceCandidate; if (result instanceof NullBean) { if (isRequired(descriptor)) { raiseNoMatchingBeanFound(type, descriptor.getResolvableType(), descriptor); } result = null; } if (!ClassUtils.isAssignableValue(type, result)) { throw new BeanNotOfRequiredTypeException(autowiredBeanName, type, instanceCandidate.getClass()); } return result; } finally { ConstructorResolver.setCurrentInjectionPoint(previousInjectionPoint); } }}2.1 确实论域型式 classObjectEntry : this.resolvableDependencies.entrySet()) { Class autowiringType = classObjectEntry.getKey(); if (autowiringType.isAssignableFrom(requiredType)) { Object autowiringValue = classObjectEntry.getValue(); autowiringValue = AutowireUtils.resolveAutowiringValue(autowiringValue, requiredType); if (requiredType.isInstance(autowiringValue)) { result.put(ObjectUtils.identityToString(autowiringValue), autowiringValue); break; } } } for (String candidate : candidateNames) { // 确实到底自己引用自己 if (!isSelfReference(beanName, candidate) && isAutowireCandidate(candidate, descriptor)) { addCandidateEntry(result, candidate, descriptor, requiredType); } } if (result.isEmpty()) { boolean multiple = indicatesMultipleBeans(requiredType); // Consider fallback matches if the first pass failed to find anything... DependencyDescriptor fallbackDescriptor = descriptor.forFallbackMatch(); for (String candidate : candidateNames) { if (!isSelfReference(beanName, candidate) && isAutowireCandidate(candidate, fallbackDescriptor) && (!multiple || getAutowireCandidateResolver().hasQualifier(descriptor))) { addCandidateEntry(result, candidate, descriptor, requiredType); } } if (result.isEmpty() && !multiple) { // Consider self references as a final pass... // but in the case of a dependency collection, not the very same bean itself. for (String candidate : candidateNames) { if (isSelfReference(beanName, candidate) && (!(descriptor instanceof MultiElementDescriptor) || !beanName.equals(candidate)) && isAutowireCandidate(candidate, fallbackDescriptor)) { addCandidateEntry(result, candidate, descriptor, requiredType); } } } } return result; }}
小孩腹胀不消化怎么办
郑州白癜风专科医院哪家好
盐城看白癜风去哪里比较好
昆明甲状腺医院哪个最好
女性更年期
慢性支气管炎咳嗽怎么治
打胎药
夜尿
类风湿性关节炎
确实必须汇入的物件的数据型式确如下几种。
StreamDependencyDescriptorArrayCollectionMappublic class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory implements ConfigurableListableBeanFactory, BeanDefinitionRegistry, Serializable { private Object resolveMultipleBeans(DependencyDescriptor descriptor, @Nullable String beanName, @Nullable Set autowiredBeanNames, @Nullable TypeConverter typeConverter) { Class type = descriptor.getDependencyType(); if (descriptor instanceof StreamDependencyDescriptor) { Map matchingBeans = findAutowireCandidates(beanName, type, descriptor); if (autowiredBeanNames != null) { autowiredBeanNames.addAll(matchingBeans.keySet()); } Stream stream = matchingBeans.keySet().stream() .map(name -> descriptor.resolveCandidate(name, type, this)) .filter(bean -> !(bean instanceof NullBean)); if (((StreamDependencyDescriptor) descriptor).isOrdered()) { stream = stream.sorted(adaptOrderComparator(matchingBeans)); } return stream; } else if (type.isArray()) { Class componentType = type.getComponentType(); ResolvableType resolvableType = descriptor.getResolvableType(); Class resolvedArrayType = resolvableType.resolve(type); if (resolvedArrayType != type) { componentType = resolvableType.getComponentType().resolve(); } if (componentType == null) { return null; } Map matchingBeans = findAutowireCandidates(beanName, componentType, new MultiElementDescriptor(descriptor)); if (matchingBeans.isEmpty()) { return null; } if (autowiredBeanNames != null) { autowiredBeanNames.addAll(matchingBeans.keySet()); } TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter()); Object result = converter.convertIfNecessary(matchingBeans.values(), resolvedArrayType); if (result instanceof Object[]) { Comparator comparator = adaptDependencyComparator(matchingBeans); if (comparator != null) { Arrays.sort((Object[]) result, comparator); } } return result; } else if (Collection.class.isAssignableFrom(type) && type.isInterface()) { Class elementType = descriptor.getResolvableType().asCollection().resolveGeneric(); if (elementType == null) { return null; } Map matchingBeans = findAutowireCandidates(beanName, elementType, new MultiElementDescriptor(descriptor)); if (matchingBeans.isEmpty()) { return null; } if (autowiredBeanNames != null) { autowiredBeanNames.addAll(matchingBeans.keySet()); } TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter()); Object result = converter.convertIfNecessary(matchingBeans.values(), type); if (result instanceof List) { if (((List) result).size()> 1) { Comparator comparator = adaptDependencyComparator(matchingBeans); if (comparator != null) { ((List) result).sort(comparator); } } } return result; } else if (Map.class == type) { ResolvableType mapType = descriptor.getResolvableType().asMap(); Class keyType = mapType.resolveGeneric(0); if (String.class != keyType) { return null; } Class valueType = mapType.resolveGeneric(1); if (valueType == null) { return null; } Map matchingBeans = findAutowireCandidates(beanName, valueType, new MultiElementDescriptor(descriptor)); if (matchingBeans.isEmpty()) { return null; } if (autowiredBeanNames != null) { autowiredBeanNames.addAll(matchingBeans.keySet()); } return matchingBeans; } else { return null; } }}2.2 查找Beanpublic class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFactory implements ConfigurableListableBeanFactory, BeanDefinitionRegistry, Serializable { protected Map findAutowireCandidates( @Nullable String beanName, Class requiredType, DependencyDescriptor descriptor) { // 通过型式给予均须型式的Bean String[] candidateNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors( this, requiredType, true, descriptor.isEager()); Map result = CollectionUtils.newLinkedHashMap(candidateNames.length); // resolvableDependencies 论域中保存了,盖子内置的和可选注册的依靠汇入单纯 //(如:HttpServletRequest单纯的汇入为该论域外部均须的单纯) for (Map.Entry以上就是Spring在汇入物件的时候都会确实是什么数据型式进行反之亦然的转换
完毕!!!
政府会:SpringBoot Cloud实战案例锦集
Spring Retry应答框架的应用
SpringBoot WebFlux整合Spring Security进行权限GMP
Spring MVC 反常处理方式 Spring事务借助基本概念软件包比对
Spring盖子这些扩展点你都清楚了吗?
Spring 可选Advisor以编程的方式借助AOP
SpringBoot邮件发送示例
SpringBoot多数据源配置古今中外
SpringBoot配置文件你认识多少?
在Spring Cloud 中你还在使用Ribbon今晚想来Load-Balancer
。贵阳风湿医院哪个好小孩腹胀不消化怎么办
郑州白癜风专科医院哪家好
盐城看白癜风去哪里比较好
昆明甲状腺医院哪个最好
女性更年期
慢性支气管炎咳嗽怎么治
打胎药
夜尿
类风湿性关节炎
相关阅读
- 颜值即正义,领导者看中你的美色,总是安排你和他出差,怎么办?
- 3000亿股票被美国冻结!俄方强势回应:或将收回阿拉斯加
- 男朋友今年35岁,年薪只有30万,或许跟他结婚吗?
- 林冲是欺软怕硬的愚蠢小人,但为何后世的人都学林冲?以耻为荣
- 多年关系很好的领导,关键提拔却同样不如你的人,还有必要处么?
- 月薪3万的领导成员对工资3千的员工说,不要只想自己KPI,多帮助他人
- 女子外出打工遭侵害,同居5个月带着生子回家,丈夫痛心疾首
- 3杯滴,你最想喝哪一杯?测你花钱有多小气,很准
- 女网红姜白鹤自曝遭性侵,续编视频寻求帮助,报警后聊天记续编被删除
- 职场中对待不知感恩,反而要「恩将仇报」的雇员,该怎么办?
- 鹅厂开源零代码、全功能、强确保的 ORM 库
- 日日思君不见君,君由此可知我一片心
- 女儿要想买高端手机,父亲不舍得还是买了,最后结局却让一个人落泪
- 郭涛:中央银行人脸识别被骗子破解 巨款不翼而飞
