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

wordpress 缩略图 剪裁 位置海外seo是什么

wordpress 缩略图 剪裁 位置,海外seo是什么,快速做网站前端的视频教程,做网站前端有前途么findAutowireCandidates()实现 1、找出BeanFactory中类型为type的所有的Bean的名字,根据BeanDefinition就能判断和当前type是不是匹配,不用生成Bean对象 2、把resolvableDependencies中key为type的对象找出来并添加到result中 3、遍历根据type找出的b…

findAutowireCandidates()实现

1、找出BeanFactory中类型为type的所有的Bean的名字,根据BeanDefinition就能判断和当前type是不是匹配,不用生成Bean对象

2、把resolvableDependencies中key为type的对象找出来并添加到result中

3、遍历根据type找出的beanName,判断当前beanName对应的Bean是不是能够被自动注入

4、先判断beanName对应的BeanDefinition中的autowireCandidate属性,如果为false,表示不能用来进行自动注入,如果为true则继续进行判断

5、判断当前type是不是泛型,如果是泛型是会把容器中所有的beanName找出来的,如果是这种情况,那么在这一步中就要获取到泛型的真正类型,然后进行匹配,如果当前beanName和当前泛型对应的真实类型匹配,那么则继续判断

6、如果当前DependencyDescriptor上存在@Qualifier注解,那么则要判断当前beanName上是否定义了Qualifier,并且是否和当前DependencyDescriptor上的Qualifier相等,相等则匹配

7、经过上述验证之后,当前beanName才能成为一个可注入的,添加到result中

/*** Find bean instances that match the required type.* Called during autowiring for the specified bean.* @param beanName the name of the bean that is about to be wired* @param requiredType the actual type of bean to look for* (may be an array component type or collection element type)* @param descriptor the descriptor of the dependency to resolve* @return a Map of candidate names and candidate instances that match* the required type (never {@code null})* @throws BeansException in case of errors* @see #autowireByType* @see #autowireConstructor*/
protected Map<String, Object> findAutowireCandidates(@Nullable String beanName, Class<?> requiredType, DependencyDescriptor descriptor) {// 从BeanFactory中找出和requiredType所匹配的beanName,仅仅是beanName,这些bean不一定经过了实例化,只有到最终确定某个Bean了,如果这个Bean还没有实例化才会真正进行实例化String[] candidateNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(this, requiredType, true, descriptor.isEager());Map<String, Object> result = CollectionUtils.newLinkedHashMap(candidateNames.length);// 根据类型从resolvableDependencies中匹配Bean,resolvableDependencies中存放的是类型:Bean对象,比如BeanFactory.class:BeanFactory对象,在Spring启动时设置for (Map.Entry<Class<?>, 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;}}}for (String candidate : candidateNames) {// 如果不是自己,则判断该candidate到底能不能用来进行自动注入if (!isSelfReference(beanName, candidate) && isAutowireCandidate(candidate, descriptor)) {addCandidateEntry(result, candidate, descriptor, requiredType);}}// 为空要么是真的没有匹配的,要么是匹配的自己if (result.isEmpty()) {// 需要匹配的类型是不是Map、数组之类的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);}}// 匹配的是自己,被自己添加到result中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;
}

依赖注入中泛型注入的实现

首先在Java反射中,有一个Type接口,表示类型,具体分类为:

1、raw types:也就是普通Class

2、parameterized types:对应ParameterizedType接口,泛型类型

3、array types:对应GenericArrayType,泛型数组

4、type variables:对应TypeVariable接口,表示类型变量,也就是所定义的泛型,比如T、K

5、primitive types:基本类型,int、boolean

public class TypeTest<T>
{private int i;private Integer it;private int[] iarray;private List list;private List<String> slist;private List<T> tlist;private T t;private T[] tarray;public static void main(String[] args) throws NoSuchFieldException{test(TypeTest.class.getDeclaredField("i"));System.out.println("=======");test(TypeTest.class.getDeclaredField("it"));System.out.println("=======");test(TypeTest.class.getDeclaredField("iarray"));System.out.println("=======");test(TypeTest.class.getDeclaredField("list"));System.out.println("=======");test(TypeTest.class.getDeclaredField("slist"));System.out.println("=======");test(TypeTest.class.getDeclaredField("tlist"));System.out.println("=======");test(TypeTest.class.getDeclaredField("t"));System.out.println("=======");test(TypeTest.class.getDeclaredField("tarray"));}public static void test(Field field){if (field.getType().isPrimitive()){System.out.println(field.getName() + "是基本数据类型");}else{System.out.println(field.getName() + "不是基本数据类型");}if (field.getGenericType() instanceof ParameterizedType){System.out.println(field.getName() + "是泛型类型");}else{System.out.println(field.getName() + "不是泛型类型");}if (field.getType().isArray()){System.out.println(field.getName() + "是普通数组");}else{System.out.println(field.getName() + "不是普通数组");}if (field.getGenericType() instanceof GenericArrayType){System.out.println(field.getName() + "是泛型数组");}else{System.out.println(field.getName() + "不是泛型数组");}if (field.getGenericType() instanceof TypeVariable){System.out.println(field.getName() + "是泛型变量");}else{System.out.println(field.getName() + "不是泛型变量");}}
}

Spring中注入点是泛型的处理:

@Component
public class UserService extends BaseService<OrderService, StockService> 
{public void test() {System.out.println(o);}
}public class BaseService<O, S> 
{@Autowiredprotected O o;@Autowiredprotected S s;
}

1、Spring扫描时发现UserService是一个Bean

2、取出注入点,也就是BaseService中的两个属性o、s

3、按注入点类型进行注入,发现o和s都是泛型,所以Spring需要确定o和s的具体类型

4、当前正在创建的是UserService的Bean,所以可以通过下面这行代码获取到具体的泛型信息

userService.getClass().getGenericSuperclass().getTypeName()
返回:
com.gax.service.BaseService<com.gax.service.OrderService, com.gax.service.StockService>

5、获取UserService的父类BaseService的泛型变量

for (TypeVariable<? extends Class<?>> typeParameter : userService.getClass().getSuperclass().getTypeParameters()) 
{System._out_.println(typeParameter.getName()); 
}

6、根据第4、5步,可以知道o对应的具体就是OrderService,s对应的具体类型就是StockService

7、调用oField.getGenericType()就知道当前field使用的是哪个泛型,得到具体类型

@Qualifier的使用

定义两个注解:

@Target({ElementType.TYPE, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Qualifier("random")
public @interface Random {
}@Target({ElementType.TYPE, ElementType.FIELD})
@Retention(RetentionPolicy.RUNTIME)
@Qualifier("roundRobin")
public @interface RoundRobin {
}

定义一个接口和两个实现类,表示负载均衡:

public interface LoadBalance 
{String select();
}@Component
@Random
public class RandomStrategy implements LoadBalance 
{@Overridepublic String select() {return null;}
}@Component
@RoundRobin
public class RoundRobinStrategy implements LoadBalance 
{@Overridepublic String select() {return null;}
}

使用:

@Component
public class UserService  
{@Autowired@RoundRobinprivate LoadBalance loadBalance;public void test() {System.out.println(loadBalance);}
}

http://www.dt0577.cn/news/27290.html

相关文章:

  • 阜宁做网站工作室长春网站seo哪家好
  • 丰田车营销网站建设的纲要计划书创建网站
  • 动漫制作专业专升本去哪个专业成都网站优化排名推广
  • 昆明做网站推永州网站seo
  • 如何做网站答题领红包链接搜索引擎排名优化方法
  • 百度快照替代百度首页关键词优化
  • 建站网站和维护需要会什么兰州网络推广与营销
  • 惠州网页建站模板推广赚钱
  • 免费建站系统下载长沙本地推广联系电话
  • 讯响模板网站下载app
  • 装修公司网站用的织梦网络营销优化培训
  • 怎么样做国外推广网站环球网广东疫情最新消息
  • 哪个网站做推广好seo页面链接优化
  • 防水网站建设湖南网站设计外包费用
  • 北京疫情最新消息今天新增哈尔滨优化网站方法
  • 渭南免费做网站公司如何把一个关键词优化到首页
  • b2c名词解释品牌关键词优化哪家便宜
  • 佛山小企业网站建设优化网站找哪家
  • 招商网站建设哪家好舆情分析报告案例
  • 福建网站开发有限开发公司电商代运营公司排名
  • 网页设计实训报告格式端点seo博客
  • 那里网站建设好地推项目发布平台
  • php网站开发环境南宁seo推广服务
  • 云南网站建设首选才力百度热议
  • 互联网基础知识入门佛山优化网站关键词
  • wordpress 加载陌生seo站点是什么意思
  • 国外vps做网站测速深圳关键词推广
  • 做mv主题网站百度公司注册地址在哪里
  • 如何建立新的企业网站网站友情链接检测
  • 网页和网站的概念seo营销技巧培训班