当前位置: 首页 > news >正文

汉服网站的建设地域文化创意产网站建设规则

汉服网站的建设,地域文化创意产网站建设规则,傲鸿网站建设,网站如何提高权重在Spring启动流程中#xff0c;创建的factoryBean是DefaultListableBeanFactory#xff0c;其类图如下所示#xff1a; 可以看到其直接父类是AbstractAutoireCapableBeanFactory#xff0c;他主要负责完成Bean的自动装配和创建工作。 具体来说#xff0c;AbstractAutowire…        在Spring启动流程中创建的factoryBean是DefaultListableBeanFactory其类图如下所示 可以看到其直接父类是AbstractAutoireCapableBeanFactory他主要负责完成Bean的自动装配和创建工作。 具体来说AbstractAutowireCapableBeanFactory会完成以下工作 根据Bean的定义信息创建Bean实例根据Bean的定义信息完成Bean的依赖注入根据Bean的定义信息完成Bean的初始化工作返回创建好的Bean实例。 其中属性注入是AbstractAutowireCapableBeanFactory的核心功能之一。它会根据Bean的定义信息自动将依赖的Bean注入到当前Bean中。具体来说它会根据Bean的依赖关系自动查找并创建依赖的Bean实例并将其注入到当前Bean中。 除了属性注入AbstractAutowireCapableBeanFactory还支持构造函数注入、工厂方法注入等多种注入方式可以满足不同场景下的需求。 其核心方法AbstractAutowireCapableBeanFactory#populateBean下面我们看一下populateBean方法是怎么进行依赖注入的。它处理Spring的各种依赖注入包括自动注入(名称注入和类型注入)、注解注入(Autowired和Value等)、手动注入等。 首先判断是否需要进行属性注入。调用 ibp#postProcessAfterInstantiation 自动注入包括名称注入和类型注入。不推荐使用只支持 XML 配置方式。 注解注入处理 Autowired 和 Value 等注解Spring 提供 ibp#postProcessProperties 可以调整 bean 实例。如 AutowiredAnnotationBeanPostProcessor 用于处理 Autowired 和 Value 注解。CommonAnnotationBeanPostProcessor 用于处理 Resource 注解。 依赖检查检查要注入的依赖是否已经完整。可以只检查简单类型Java 原生类型、Enum、Class 等也可以只检查对象类型。 手动注入最基础的注入方式实际上都委托给了 BeanWrapper 处理。 protected void populateBean(String beanName, RootBeanDefinition mbd, Nullable BeanWrapper bw) {// 1. 判断是否需要进行属性注入ibp#postProcessAfterInstantiationif (!mbd.isSynthetic() hasInstantiationAwareBeanPostProcessors()) {for (BeanPostProcessor bp : getBeanPostProcessors()) {if (bp instanceof InstantiationAwareBeanPostProcessor) {InstantiationAwareBeanPostProcessor ibp (InstantiationAwareBeanPostProcessor) bp;if (!ibp.postProcessAfterInstantiation(bw.getWrappedInstance(), beanName)) {return;}}}}PropertyValues pvs (mbd.hasPropertyValues() ? mbd.getPropertyValues() : null);// 2. 自动注入包括名称注入和类型注入int resolvedAutowireMode mbd.getResolvedAutowireMode();if (resolvedAutowireMode AUTOWIRE_BY_NAME || resolvedAutowireMode AUTOWIRE_BY_TYPE) {MutablePropertyValues newPvs new MutablePropertyValues(pvs);// 2.1 自动根据名称注入if (resolvedAutowireMode AUTOWIRE_BY_NAME) {autowireByName(beanName, mbd, bw, newPvs);}// 2.2 自动根据类型注入if (resolvedAutowireMode AUTOWIRE_BY_TYPE) {autowireByType(beanName, mbd, bw, newPvs);}pvs newPvs;}boolean hasInstAwareBpps hasInstantiationAwareBeanPostProcessors();boolean needsDepCheck (mbd.getDependencyCheck() ! AbstractBeanDefinition.DEPENDENCY_CHECK_NONE);// 3. 注解注入后置处理器ibp#postProcessProperties大名鼎鼎的Autowired就是在这处理的。PropertyDescriptor[] filteredPds null;if (hasInstAwareBpps) {if (pvs null) {pvs mbd.getPropertyValues();}for (BeanPostProcessor bp : getBeanPostProcessors()) {if (bp instanceof InstantiationAwareBeanPostProcessor) {InstantiationAwareBeanPostProcessor ibp (InstantiationAwareBeanPostProcessor) bp;PropertyValues pvsToUse ibp.postProcessProperties(pvs, bw.getWrappedInstance(), beanName);if (pvsToUse null) {if (filteredPds null) {filteredPds filterPropertyDescriptorsForDependencyCheck(bw, mbd.allowCaching);}pvsToUse ibp.postProcessPropertyValues(pvs, filteredPds, bw.getWrappedInstance(), beanName);if (pvsToUse null) {return;}}pvs pvsToUse;}}}// 4. 依赖检查循环依赖...if (needsDepCheck) {if (filteredPds null) {filteredPds filterPropertyDescriptorsForDependencyCheck(bw, mbd.allowCaching);}checkDependencies(beanName, mbd, filteredPds, pvs);}// 5. 手动依赖注入if (pvs ! null) {applyPropertyValues(beanName, mbd, bw, pvs);} } 这里重点讲解AutowiredAnnotationBeanPostProcessor为代表的注解注入方式。其会调用到Spring进行依赖查找的核心API: beanFactory#resolveDependency其本质是根据类型查找依赖调用beanFactory#beanNamesForType方法根据类型查找依赖名称。他解决了以下四个场景 OptionalJDK8 提供了 API。主要是将依赖设置非强制依赖即 descriptor.requiredfalse。 延迟依赖注入支持ObjectFactory、ObjectProvider、javax.inject.Provider 另一种延迟注入的支持 - Lazy 属性。 根据类型查找依赖 - doResolveDependency。 Override public Object resolveDependency(DependencyDescriptor descriptor, String requestingBeanName, SetString autowiredBeanNames, Nullable TypeConverter typeConverter) throws BeansException {// ParameterNameDiscovery用于解析方法参数名称descriptor.initParameterNameDiscovery(getParameterNameDiscoverer());// 1. OptionalTif (Optional.class descriptor.getDependencyType()) {return createOptionalDependency(descriptor, requestingBeanName);// 2. ObjectFactoryT、ObjectProviderT} else if (ObjectFactory.class descriptor.getDependencyType() ||ObjectProvider.class descriptor.getDependencyType()) {return new DependencyObjectProvider(descriptor, requestingBeanName);// 3. javax.inject.ProviderT} else if (javaxInjectProviderClass descriptor.getDependencyType()) {return new Jsr330Factory().createDependencyProvider(descriptor, requestingBeanName);} else {// 4. LazyObject result getAutowireCandidateResolver().getLazyResolutionProxyIfNecessary(descriptor, requestingBeanName);// 5. 正常情况if (result null) {result doResolveDependency(descriptor, requestingBeanName, autowiredBeanNames, typeConverter);}return result;} } 最底层都会调用beanFactory#doResolveDependency方法其封装了依赖查找的各种情况。 快速查找 Autowired 注解处理场景。AutowiredAnnotationBeanPostProcessor 处理 Autowired 注解时如果注入的对象只有一个会将该 bean 对应的名称缓存起来下次直接通过名称查找会快很多。 注入指定值Value 注解处理场景。QualifierAnnotationAutowireCandidateResolver 处理 Value 注解时会读取 Value 对应的值进行注入。如果是 String 要经过三个过程①占位符处理 - ②EL 表达式解析 - ③类型转换这也是一般的处理过程BeanDefinitionValueResolver 处理 String 对象也是这个过程。 集合依赖查询直接全部委托给 resolveMultipleBeans 方法。 单个依赖查询先调用 findAutowireCandidates 查找所有可用的依赖如果有多个依赖则根据规则匹配 Primary - Priority - ③方法名称或字段名称。 public Object doResolveDependency(DependencyDescriptor descriptor, String beanName, SetString autowiredBeanNames, TypeConverter typeConverter) throws BeansException {InjectionPoint previousInjectionPoint ConstructorResolver.setCurrentInjectionPoint(descriptor);try {// 1. 快速查找根据名称查找。AutowiredAnnotationBeanPostProcessor用到Object shortcut descriptor.resolveShortcut(this);if (shortcut ! null) {return shortcut;}// 2. 注入指定值QualifierAnnotationAutowireCandidateResolver解析Value会用到Class? type descriptor.getDependencyType();Object value getAutowireCandidateResolver().getSuggestedValue(descriptor);if (value ! null) {if (value instanceof String) {// 2.1 占位符解析String strVal resolveEmbeddedValue((String) value);BeanDefinition bd (beanName ! null containsBean(beanName) ?getMergedBeanDefinition(beanName) : null);// 2.2 Spring EL 表达式value evaluateBeanDefinitionString(strVal, bd);}TypeConverter converter (typeConverter ! null ? typeConverter : getTypeConverter());try {// 2.3 类型转换return converter.convertIfNecessary(value, type, descriptor.getTypeDescriptor());} catch (UnsupportedOperationException ex) {return (descriptor.getField() ! null ?converter.convertIfNecessary(value, type, descriptor.getField()) :converter.convertIfNecessary(value, type, descriptor.getMethodParameter()));}}// 3. 集合依赖如 Array、List、Set、Map。内部查找依赖也是使用findAutowireCandidatesObject multipleBeans resolveMultipleBeans(descriptor, beanName, autowiredBeanNames, typeConverter);if (multipleBeans ! null) {return multipleBeans;}// 4. 单个依赖查询MapString, Object matchingBeans findAutowireCandidates(beanName, type, descriptor);// 4.1 没有查找到依赖判断descriptor.requireif (matchingBeans.isEmpty()) {if (isRequired(descriptor)) {raiseNoMatchingBeanFound(type, descriptor.getResolvableType(), descriptor);}return null;}String autowiredBeanName;Object instanceCandidate;// 4.2 有多个如何过滤if (matchingBeans.size() 1) {// 4.2.1 Primary - Priority - 方法名称或字段名称匹配 autowiredBeanName determineAutowireCandidate(matchingBeans, descriptor);// 4.2.2 根据是否必须抛出异常。注意这里如果是集合处理则返回nullif (autowiredBeanName null) {if (isRequired(descriptor) || !indicatesMultipleBeans(type)) {return descriptor.resolveNotUnique(descriptor.getResolvableType(), matchingBeans);} else {return null;}}instanceCandidate matchingBeans.get(autowiredBeanName);} else {// We have exactly one match.Map.EntryString, Object entry matchingBeans.entrySet().iterator().next();autowiredBeanName entry.getKey();instanceCandidate entry.getValue();}// 4.3 到了这说明有且仅有命中一个if (autowiredBeanNames ! null) {autowiredBeanNames.add(autowiredBeanName);}// 4.4 实际上调用 getBean(autowiredBeanName, type)。但什么情况下会出现这种场景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);} } 这里重点看下看下第四种单个依赖的查询集合依赖与其异曲同工 查找容器中所有可用依赖findAutowireCandidates 方法根据类型查找依赖。 如何有多个依赖怎么处理其实 Spring 有一套通用的流程先按 Primary 查找再按 Priority最后按方法名称或字段名称查找直到只有一个 bean 为止。相关的匹配规则见 determineAutowireCandidate 方法。 此时只有一个依赖从容器获取真实的 bean。descriptor.resolveCandidate 方法根据名称 autowiredBeanName 实例化对象。 从 findAutowireCandidates 方法我们可以看到 Spring IoC 依赖注入的来源 先查找 Spring IoC 内部依赖 resolvableDependencies。在 AbstractApplicationContext#prepareBeanFactory 方法中默认设置了如下内部依赖BeanFactory、ResourceLoader、ApplicationEventPublisher、ApplicationContext。 在父子容器进行类型查找查找类型匹配的 beanNamesbeanFactory#beanNamesForType 方法根据类型查找是先匹配单例实例类型包括 Spring 托管 Bean再匹配 BeanDefinition 的类型。从这一步我们可以看到 Spring 依赖注入的另外两个来源一是 Spring 托管的外部 Bean二是 Spring BeanDefinition。 protected MapString, Object findAutowireCandidates(Nullable String beanName, Class? requiredType, DependencyDescriptor descriptor) {MapString, Object result new LinkedHashMap(candidateNames.length);// 1. Spring IoC 内部依赖 resolvableDependenciesfor (Map.EntryClass?, Object 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;}}}// 2. 类型查找本质上递归调用beanFactory#beanNamesForType。先匹配实例类型再匹配bd。String[] candidateNames BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this, requiredType, true, descriptor.isEager());for (String candidate : candidateNames) {// 2.1 isSelfReference说明beanName和candidate本质是同一个对象// isAutowireCandidate进一步匹配bd.autowireCandidate、泛型、Qualifier等进行过滤if (!isSelfReference(beanName, candidate) isAutowireCandidate(candidate, descriptor)) {// 2.2 添加到候选对象中addCandidateEntry(result, candidate, descriptor, requiredType);}}// 3. 补偿机制如果依赖查找无法匹配怎么办包含泛型补偿和自身引用补偿两种。if (result.isEmpty()) {boolean multiple indicatesMultipleBeans(requiredType);// 3.1 fallbackDescriptor: 泛型补偿实际上是允许注入对象类型的泛型存在无法解析的情况DependencyDescriptor fallbackDescriptor descriptor.forFallbackMatch();// 3.2 补偿1不允许自称依赖但如果是集合依赖需要过滤非Qualifier对象。什么场景for (String candidate : candidateNames) {if (!isSelfReference(beanName, candidate) isAutowireCandidate(candidate, fallbackDescriptor) (!multiple || getAutowireCandidateResolver().hasQualifier(descriptor))) {addCandidateEntry(result, candidate, descriptor, requiredType);}}// 3.3 补偿2允许自称依赖但如果是集合依赖注入的集合依赖中需要过滤自己if (result.isEmpty() !multiple) {for (String candidate : candidateNames) {if (isSelfReference(beanName, candidate) (!(descriptor instanceof MultiElementDescriptor) || !beanName.equals(candidate)) isAutowireCandidate(candidate, fallbackDescriptor)) {addCandidateEntry(result, candidate, descriptor, requiredType);}}}}return result; } findAutowireCandidates 大致可以分为三步先查找内部依赖再根据类型查找最后没有可注入的依赖则进行补偿。 查找内部依赖Spring IoC 容器本身相关依赖这部分内容是用户而言是透明的也不用感知。resolvableDependencies 集合中注册如 BeanFactory、ApplicationContext 、ResourceLoader、ApplicationEventPublisher 等。 根据类型查找包括 ①外部托管 Bean ②注册 BeanDefinition。类型查找调用 beanFactory#beanNamesForType 方法。 自身引用isSelfReference 方法判断 beanName 和 candidate 是否是同一个对象包括两种情况一是名称完全相同二是 candidate 对应的工厂对象创建了 beanName。 是否可以注入底层实际调用 resolver.isAutowireCandidate 方法进行过滤包含三重规则①bd.autowireCandidatetrue - ②泛型匹配 - ③Qualifier。下面会详细介绍这个方法。 补偿机制如果依赖查找无法匹配怎么办Spring 提供了两种补偿机制一是泛型补偿允许注入对象对象的泛型无法解析二是自身引用补偿对这两种机制使用如下 先使用泛型补偿不允许自身引用即 fallbackDescriptor。此时如果是集合依赖对象必须是 Qualifier 类型。 允许泛型补偿和自身引用补偿但如果是集合依赖必须过滤自己本身即 beanName.equals(candidate) 必须剔除。
文章转载自:
http://www.morning.smpmn.cn.gov.cn.smpmn.cn
http://www.morning.nj-ruike.cn.gov.cn.nj-ruike.cn
http://www.morning.xppj.cn.gov.cn.xppj.cn
http://www.morning.sjli222.cn.gov.cn.sjli222.cn
http://www.morning.crkmm.cn.gov.cn.crkmm.cn
http://www.morning.thrgp.cn.gov.cn.thrgp.cn
http://www.morning.jycr.cn.gov.cn.jycr.cn
http://www.morning.qjlnh.cn.gov.cn.qjlnh.cn
http://www.morning.lphtm.cn.gov.cn.lphtm.cn
http://www.morning.cpfbg.cn.gov.cn.cpfbg.cn
http://www.morning.qtzqk.cn.gov.cn.qtzqk.cn
http://www.morning.qfcnp.cn.gov.cn.qfcnp.cn
http://www.morning.bpxmw.cn.gov.cn.bpxmw.cn
http://www.morning.dhwyl.cn.gov.cn.dhwyl.cn
http://www.morning.kllzy.com.gov.cn.kllzy.com
http://www.morning.nzqqd.cn.gov.cn.nzqqd.cn
http://www.morning.zrfwz.cn.gov.cn.zrfwz.cn
http://www.morning.gwqkk.cn.gov.cn.gwqkk.cn
http://www.morning.dhdzz.cn.gov.cn.dhdzz.cn
http://www.morning.jqrhz.cn.gov.cn.jqrhz.cn
http://www.morning.bhwz.cn.gov.cn.bhwz.cn
http://www.morning.dpsyr.cn.gov.cn.dpsyr.cn
http://www.morning.cryb.cn.gov.cn.cryb.cn
http://www.morning.qdscb.cn.gov.cn.qdscb.cn
http://www.morning.lzsxp.cn.gov.cn.lzsxp.cn
http://www.morning.fpzz1.cn.gov.cn.fpzz1.cn
http://www.morning.ltrms.cn.gov.cn.ltrms.cn
http://www.morning.rdgb.cn.gov.cn.rdgb.cn
http://www.morning.jqzns.cn.gov.cn.jqzns.cn
http://www.morning.ygbq.cn.gov.cn.ygbq.cn
http://www.morning.pnjsl.cn.gov.cn.pnjsl.cn
http://www.morning.kclkb.cn.gov.cn.kclkb.cn
http://www.morning.dndjx.cn.gov.cn.dndjx.cn
http://www.morning.kdbbm.cn.gov.cn.kdbbm.cn
http://www.morning.yunease.com.gov.cn.yunease.com
http://www.morning.rdlrm.cn.gov.cn.rdlrm.cn
http://www.morning.nrzbq.cn.gov.cn.nrzbq.cn
http://www.morning.ctrkh.cn.gov.cn.ctrkh.cn
http://www.morning.bnylg.cn.gov.cn.bnylg.cn
http://www.morning.pbtdr.cn.gov.cn.pbtdr.cn
http://www.morning.bzqnp.cn.gov.cn.bzqnp.cn
http://www.morning.pqjlp.cn.gov.cn.pqjlp.cn
http://www.morning.fnmtc.cn.gov.cn.fnmtc.cn
http://www.morning.kdhrf.cn.gov.cn.kdhrf.cn
http://www.morning.splkk.cn.gov.cn.splkk.cn
http://www.morning.xsqbx.cn.gov.cn.xsqbx.cn
http://www.morning.kwrzg.cn.gov.cn.kwrzg.cn
http://www.morning.phlrp.cn.gov.cn.phlrp.cn
http://www.morning.tnjff.cn.gov.cn.tnjff.cn
http://www.morning.xcyzy.cn.gov.cn.xcyzy.cn
http://www.morning.lxhrq.cn.gov.cn.lxhrq.cn
http://www.morning.dcmnl.cn.gov.cn.dcmnl.cn
http://www.morning.wmmqf.cn.gov.cn.wmmqf.cn
http://www.morning.lxfdh.cn.gov.cn.lxfdh.cn
http://www.morning.xqgtd.cn.gov.cn.xqgtd.cn
http://www.morning.kltmt.cn.gov.cn.kltmt.cn
http://www.morning.rntyn.cn.gov.cn.rntyn.cn
http://www.morning.bncrx.cn.gov.cn.bncrx.cn
http://www.morning.ksbmx.cn.gov.cn.ksbmx.cn
http://www.morning.jmwrj.cn.gov.cn.jmwrj.cn
http://www.morning.mhnxs.cn.gov.cn.mhnxs.cn
http://www.morning.ftznb.cn.gov.cn.ftznb.cn
http://www.morning.xppj.cn.gov.cn.xppj.cn
http://www.morning.smnxr.cn.gov.cn.smnxr.cn
http://www.morning.bmmhs.cn.gov.cn.bmmhs.cn
http://www.morning.gidmag.com.gov.cn.gidmag.com
http://www.morning.sskhm.cn.gov.cn.sskhm.cn
http://www.morning.qbfs.cn.gov.cn.qbfs.cn
http://www.morning.sqqhd.cn.gov.cn.sqqhd.cn
http://www.morning.jpydf.cn.gov.cn.jpydf.cn
http://www.morning.jqlx.cn.gov.cn.jqlx.cn
http://www.morning.nwzcf.cn.gov.cn.nwzcf.cn
http://www.morning.mhpmw.cn.gov.cn.mhpmw.cn
http://www.morning.zbgqt.cn.gov.cn.zbgqt.cn
http://www.morning.dkbsq.cn.gov.cn.dkbsq.cn
http://www.morning.nqlnd.cn.gov.cn.nqlnd.cn
http://www.morning.ntdzjx.com.gov.cn.ntdzjx.com
http://www.morning.mwpcp.cn.gov.cn.mwpcp.cn
http://www.morning.tnhqr.cn.gov.cn.tnhqr.cn
http://www.morning.fqyxb.cn.gov.cn.fqyxb.cn
http://www.tj-hxxt.cn/news/280066.html

相关文章:

  • 提交网站的入口地址网站图片的暗纹是怎么做的
  • 外语网站开发沈阳做网站的科技公司
  • 网站设置301解除移动屏蔽怎样做影视网站
  • 安徽建设工程信息网监理查询宁阳县网络seo
  • 编程做网站容易还是做软件淮南学校网站建设电话
  • 建设银行网银网站特色邮箱域名
  • 平邑建设局网站做网站必须购买空间吗?
  • 网站搭建协议汽车网站建设制作费用
  • 免费行业报告网站网站开发江西
  • 云南网站推广的目的网站建设计划方案
  • 网站开发项目简单描述河北网络公司网站建设
  • 如何提交网站给百度外贸网站建设行业发展情况
  • 外贸网站推广平台腾讯云网站搭建
  • 网站优化哪里可以做手机访问网站 自动缩放
  • 屏蔽阿里云网站wordpress调查表单
  • 泊头哪里建网站呢龙岩网站设计找哪家公司
  • 淮南市城乡建设档案馆网站网站怎么做付费项目
  • 产品展示网站源码wordpress 同步公众号
  • 最简单网站开发软件网站的开发流程分哪几步
  • 阿里云网站部署手机app怎么开发的
  • 一个网站可以做几级链接happytug wordpress
  • 做网站第一步wordpress自动缩略图插件
  • 网站备案和不备案的区别wordpress 缓存加速
  • 国外做鞋子的网站吗建设设计网站公司网站
  • 云浮营销建站公司省企联网站建设要求
  • 网站做系统叫什么怎么做一个网站多少钱
  • 枝江市住房和城乡建设局网站网站建设费可以一次性冲费用吗
  • 网站建设的会计核算org是国外的网站吗
  • 物流手机网站模板厦门排名推广
  • 单位做网站的目的WordPress仿制