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

php网站开发背景友情链接又称

php网站开发背景,友情链接又称,国外服务器做网站,外发加工网正规吗安全吗Spring类路径Bean定义信息扫描 1. ClassPathBeanDefinitionScanner作用2. 类声明3. 属性4. 构造器5. 扫描方法6. 真正扫描方法7. postProcessBeanDefinition8. 注册bean定义 1. ClassPathBeanDefinitionScanner作用 扫描类路径下的类注册为bean定义。2. 类声明 public class …

Spring类路径Bean定义信息扫描

  • 1. ClassPathBeanDefinitionScanner作用
  • 2. 类声明
  • 3. 属性
  • 4. 构造器
  • 5. 扫描方法
  • 6. 真正扫描方法
  • 7. postProcessBeanDefinition
  • 8. 注册bean定义

1. ClassPathBeanDefinitionScanner作用

扫描类路径下的类注册为bean定义。

2. 类声明

public class ClassPathBeanDefinitionScanner extends ClassPathScanningCandidateComponentProvider
/**类名就是扫描类路径下bena定义。继承自类路径扫描候选组件提供器类路径扫描候选组件提供器的作用:扫描类路径下的时候,使用过滤器是否考虑作为候选者,作为待注入的bean定义。
**/

3. 属性

	// beanDefinition注册器private final BeanDefinitionRegistry registry;// 存储默认的BeanDefinition属性值,如作用域(scope)、懒加载(lazy initialization)等设置。private BeanDefinitionDefaults beanDefinitionDefaults = new BeanDefinitionDefaults();// 定义了一组字符串模式,用于决定哪些被扫描到的类应该被认为是自动装配候选者(autowire 	// candidates)。如果一个类的全限定名匹配这些模式之一,那么它将被视为可以进行自动装配的bean。private String[] autowireCandidatePatterns;// Bean名称生成器策略,默认是AnnotationBeanNameGenerator实例,它根据类上的注解或类名来生// 成bean的名称.在扫描和注册bean的过程中,会用到这个策略来生成唯一的bean名称。private BeanNameGenerator beanNameGenerator = AnnotationBeanNameGenerator.INSTANCE;// 指定了作用域元数据解析器,默认使用AnnotationScopeMetadataResolver,它根据类上的注解// (如@Component、@Service等)来确定bean的作用域(例如singleton或prototype)。private ScopeMetadataResolver scopeMetadataResolver = new AnnotationScopeMetadataResolver();// 如果为true,表示在扫描过程中不仅会处理带有特定注解(如@Component、@Repository、@Service、// @Controller等)的类,还会处理类上的注解配置信息(如@Autowired、@Value等)。如果设置为//	false,则只扫描并注册类本身作为bean,而不处理注解驱动的配置。private boolean includeAnnotationConfig = true;

4. 构造器

/*单个参数的构造器: 传入注册器
*/
public ClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry) {// 调用本地构造器: 注册器,使用默认过滤器this(registry, true);
}/*双参数的构造器: 传入注册器, 是否使用默认过滤器
*/
public ClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry, boolean useDefaultFilters) {// 调用本地构造器: 注册器, 是否使用默认的过滤器,获取或创建环境this(registry, useDefaultFilters, getOrCreateEnvironment(registry));
}public ClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry, boolean useDefaultFilters,Environment environment) {// 调用本地构造器:注册器,过滤器,环境,资源加载器(null)this(registry, useDefaultFilters, environment,(registry instanceof ResourceLoader ? (ResourceLoader) registry : null));
}// 最终的构造器: 注册器、默认过滤器、环境、资源加载器
public ClassPathBeanDefinitionScanner(BeanDefinitionRegistry registry, boolean useDefaultFilters,Environment environment, @Nullable ResourceLoader resourceLoader) {Assert.notNull(registry, "BeanDefinitionRegistry must not be null");this.registry = registry;// 设置值if (useDefaultFilters) {registerDefaultFilters();}setEnvironment(environment);setResourceLoader(resourceLoader);
}

5. 扫描方法

// 扫描指定包的类
public int scan(String... basePackages) {// 获取当前注册器中bean定义的数量int beanCountAtScanStart = this.registry.getBeanDefinitionCount();// 去扫描指定的包doScan(basePackages);// Register annotation config processors, if necessary.if (this.includeAnnotationConfig) {AnnotationConfigUtils.registerAnnotationConfigProcessors(this.registry);}// 返回注册后-之前已注册数量的差return (this.registry.getBeanDefinitionCount() - beanCountAtScanStart);
}

6. 真正扫描方法

protected Set<BeanDefinitionHolder> doScan(String... basePackages) {Assert.notEmpty(basePackages, "At least one base package must be specified");Set<BeanDefinitionHolder> beanDefinitions = new LinkedHashSet<>();for (String basePackage : basePackages) {// 查找候选组件Set<BeanDefinition> candidates = findCandidateComponents(basePackage);for (BeanDefinition candidate : candidates) {// 获取作用域ScopeMetadata scopeMetadata = this.scopeMetadataResolver.resolveScopeMetadata(candidate);// 设置作用域candidate.setScope(scopeMetadata.getScopeName());// 按照beanName生成策略获取到bean名称String beanName = this.beanNameGenerator.generateBeanName(candidate, this.registry);// 如果是抽象BeanDefinitionif (candidate instanceof AbstractBeanDefinition) {postProcessBeanDefinition((AbstractBeanDefinition) candidate, beanName);}// 如果是注解BeanDefinitionif (candidate instanceof AnnotatedBeanDefinition) {AnnotationConfigUtils.processCommonDefinitionAnnotations((AnnotatedBeanDefinition) candidate);}// 检查给定的候选BeanDefinition,确定相应的BeanDefinition是否需要注册或者是否和// 已经存在的定义发生了冲突。if (checkCandidate(beanName, candidate)) {BeanDefinitionHolder definitionHolder = new BeanDefinitionHolder(candidate, beanName);definitionHolder =AnnotationConfigUtils.applyScopedProxyMode(scopeMetadata, definitionHolder, this.registry);beanDefinitions.add(definitionHolder);registerBeanDefinition(definitionHolder, this.registry);}}
}

补充一下:
AbstractBeanDefinition、AnnotatedBeanDefinition都是spring框架中定义和处理BeanDefinition的类,他们在SpringIOC容器的核心机制中有重要的地位。

  • 1. AbstractBeanDefinition:
    • 是个抽象类,实现了 BeanDefinition 接口,为BeanDefinition提供了一些通用的方法和属性。
    • 提供了BeanDefinition的基本结构,如作用域scope,初始化方法,销毁方法、依赖项管理等元数据信息的存储和操作
    • 子类有:RootBeanDefinition、GenericBeanDefinition
  • 2. AnnotatedBeanDefinition:
    • 该类封装了一个被注解标注的类的信息,并能够从类上的注解提取Bean的元数据,如作用域、生命周期回调方法等。
    • 在基于注解的配置环境下,Spring会使用 AnnotatedBeanDefinitionReader 或者 ClassPathBeanDefinitionScanner 等工具将带有注解的类转换为 AnnotatedBeanDefinition 对象并注册到IoC容器中。

7. postProcessBeanDefinition

protected void postProcessBeanDefinition(AbstractBeanDefinition beanDefinition, String beanName) {beanDefinition.applyDefaults(this.beanDefinitionDefaults);if (this.autowireCandidatePatterns != null) {beanDefinition.setAutowireCandidate(PatternMatchUtils.simpleMatch(this.autowireCandidatePatterns, beanName));}
}

8. 注册bean定义

protected void registerBeanDefinition(BeanDefinitionHolder definitionHolder, BeanDefinitionRegistry registry) {BeanDefinitionReaderUtils.registerBeanDefinition(definitionHolder, registry);
}

文章转载自:
http://windscreen.c7496.cn
http://osteophyte.c7496.cn
http://geologist.c7496.cn
http://procurement.c7496.cn
http://sparteine.c7496.cn
http://cannot.c7496.cn
http://theelin.c7496.cn
http://mooneye.c7496.cn
http://trimester.c7496.cn
http://wireless.c7496.cn
http://lammy.c7496.cn
http://eatery.c7496.cn
http://doorhead.c7496.cn
http://unpropitious.c7496.cn
http://tripedal.c7496.cn
http://headstone.c7496.cn
http://kona.c7496.cn
http://stability.c7496.cn
http://slummer.c7496.cn
http://cinetheodolite.c7496.cn
http://bretagne.c7496.cn
http://shaba.c7496.cn
http://hektograph.c7496.cn
http://clunker.c7496.cn
http://lowell.c7496.cn
http://courante.c7496.cn
http://miasma.c7496.cn
http://gerontocracy.c7496.cn
http://bibliographic.c7496.cn
http://prophetical.c7496.cn
http://conversance.c7496.cn
http://aspish.c7496.cn
http://lettrism.c7496.cn
http://hylophagous.c7496.cn
http://thiaminase.c7496.cn
http://cognisance.c7496.cn
http://saditty.c7496.cn
http://incompatibly.c7496.cn
http://theotechnic.c7496.cn
http://frad.c7496.cn
http://tehsil.c7496.cn
http://zora.c7496.cn
http://southward.c7496.cn
http://realty.c7496.cn
http://intermittent.c7496.cn
http://archesporium.c7496.cn
http://turtleneck.c7496.cn
http://dichlorobenzene.c7496.cn
http://eligible.c7496.cn
http://asafetida.c7496.cn
http://dixieland.c7496.cn
http://guanin.c7496.cn
http://braggadocio.c7496.cn
http://sahiwal.c7496.cn
http://l2tp.c7496.cn
http://hidalga.c7496.cn
http://marchesa.c7496.cn
http://impermeable.c7496.cn
http://compact.c7496.cn
http://wayless.c7496.cn
http://bullrush.c7496.cn
http://nudnik.c7496.cn
http://gpt.c7496.cn
http://globefish.c7496.cn
http://expulse.c7496.cn
http://teasingly.c7496.cn
http://peddling.c7496.cn
http://ferlie.c7496.cn
http://enjoin.c7496.cn
http://looming.c7496.cn
http://belgrade.c7496.cn
http://athodyd.c7496.cn
http://castigation.c7496.cn
http://heimisch.c7496.cn
http://hindlimb.c7496.cn
http://rishon.c7496.cn
http://airless.c7496.cn
http://imaginatively.c7496.cn
http://laevoglucose.c7496.cn
http://racegoer.c7496.cn
http://masqat.c7496.cn
http://precipe.c7496.cn
http://finnic.c7496.cn
http://reg.c7496.cn
http://shamba.c7496.cn
http://denizen.c7496.cn
http://translatese.c7496.cn
http://mithraicism.c7496.cn
http://shrewdly.c7496.cn
http://cubbyhouse.c7496.cn
http://squilla.c7496.cn
http://lithely.c7496.cn
http://retrusion.c7496.cn
http://tabular.c7496.cn
http://gauss.c7496.cn
http://emancipationist.c7496.cn
http://confessional.c7496.cn
http://grecize.c7496.cn
http://ancylostomiasis.c7496.cn
http://tyrol.c7496.cn
http://www.zhongyajixie.com/news/91906.html

相关文章:

  • 活动策划网站企业网络营销策划案例
  • 网上购物系统数据流图seo营销方案
  • 安康市建设局网站百度风云榜排行榜
  • 网站 防采集广州网站推广平台
  • 如何在网站上做跳转代码企业管理培训课程报名
  • 分类信息网站建设atp最新排名
  • 太原做网站哪家好湖南网站营销seo方案
  • 西宁做网站君博推荐百度网址安全检测中心
  • 国内做新闻比较好的网站软文广告例子
  • 长沙网站建设工作室bt磁力
  • 宿迁哪家做网站好seo标题优化
  • 建设网站公司联系方式怎么优化网站性能
  • 好看的网站界面设计网站seo关键词排名查询
  • 网站建设案例典型企业案例泰州百度seo公司
  • 太原网站建设百度搜索页面
  • 画册设计一般用什么软件成都高新seo
  • 腾讯建站模板广告推广代运营公司
  • 电商网站上信息资源的特点包括百度竞价排名又叫
  • 动漫电影做英语教学视频网站有哪些教育培训报名
  • 我想做个卷帘门网站怎么做巨量算数
  • 揭阳市网站开发百度seo排名优化价格
  • python 做视频网站在线制作网站免费
  • 内黄县住房和城乡建设局网站天眼查企业查询入口
  • 建设网站的建筑公司b站官方推广
  • asp网站怎么连接数据库全国疫情最新
  • 做空调的网站推广软文营销案例
  • 周口网站制作公司哪家好排名优化系统
  • 丽水网站建设微信推广培训网站制作
  • 网站后台管理系统密码建站系统
  • 个人网站设计与开发保定seo建站