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

为什么国外网站有时打不开seo免费培训视频

为什么国外网站有时打不开,seo免费培训视频,常州关键词优化如何,网站建设网络推广图片1 自动配置原理剖析 1.1 加载配置类的源码追溯 自动配置的触发入口: SpringBootApplication 组合注解是自动配置的起点,其核心包含 EnableAutoConfiguration,该注解使用AutoConfigurationImportSelector 实现配置类的动态加载。 启动类的注…

1 自动配置原理剖析

1.1 加载配置类的源码追溯

  1. 自动配置的触发入口: @SpringBootApplication 组合注解是自动配置的起点,其核心包含 @EnableAutoConfiguration,该注解使用AutoConfigurationImportSelector 实现配置类的动态加载。

ALt

启动类的注解@SpringBootApplication

//可以应用于类、接口(包括注解类型)和枚举声明
@Target(ElementType.TYPE)
//注解信息将在运行时保留
@Retention(RetentionPolicy.RUNTIME)
//在使用 Javadoc 工具生成 API 文档时,该注解将被包含在文档中
@Documented
//如果一个类使用了@SpringBootApplication 注解,那么它的子类也会继承这个注解
@Inherited
//springboot配置类
@SpringBootConfiguration
//核心:启用Spring Boot 的自动配置机制
@EnableAutoConfiguration
//启用组件扫描
@ComponentScan(excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication{}
@SpringBootApplication注解
  1. 查看@EnableAutoConfiguration,@EnableAutoConfiguration注解上导入了AutoConfigurationImportSelector.class,该类负责选择和导入需要自动配置的类
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
//指定自动配置的包路径,通常用于扫描带有@Configuration 注解的类
@AutoConfigurationPackage
@Import(AutoConfigurationImportSelector.class)
public @interface EnableAutoConfiguration {}
3 @EnableAutoConfiguration注解
  1. 查看AutoConfigurationImportSelector.class,该类负责加载、筛选和返回需要加载的自动配置类
public class AutoConfigurationImportSelector implements ... {// 核心方法:选择并加载自动配置类
@Override
public String[] selectImports(AnnotationMetadata annotationMetadata) {// 1. 检查是否启用自动配置if (!isEnabled(annotationMetadata)) {return NO_IMPORTS; // 如果未启用,返回空数组}// 2. 获取自动配置条目AutoConfigurationEntry autoConfigurationEntry = getAutoConfigurationEntry(annotationMetadata);// 3. 返回配置类数组return StringUtils.toStringArray(autoConfigurationEntry.getConfigurations());
}
  1. 查看selectImports中调用的getAutoConfigurationEntry方法。
protected AutoConfigurationEntry getAutoConfigurationEntry(AnnotationMetadata annotationMetadata) {// 1. 检查是否启用自动配置if (!isEnabled(annotationMetadata)) {return EMPTY_ENTRY; // 如果未启用,返回空条目}// 2. 获取注解属性AnnotationAttributes attributes = getAttributes(annotationMetadata);// 3. 加载候选配置类List<String> configurations = getCandidateConfigurations(annotationMetadata, attributes);// 4. 去重configurations = removeDuplicates(configurations);// 5. 获取排除项Set<String> exclusions = getExclusions(annotationMetadata, attributes);// 6. 检查排除项checkExcludedClasses(configurations, exclusions);// 7. 过滤排除项configurations.removeAll(exclusions);// 8. 应用配置类过滤器configurations = getConfigurationClassFilter().filter(configurations);// 9. 触发事件fireAutoConfigurationImportEvents(configurations, exclusions);// 10. 返回结果return new AutoConfigurationEntry(configurations, exclusions);
}
  1. 查看getAutoConfigurationEntry方法调用的getCandidateConfigurations方法
protected List<String> getCandidateConfigurations(AnnotationMetadata metadata, AnnotationAttributes attributes) {// 1. 加载候选配置类ImportCandidates importCandidates = ImportCandidates.load(this.autoConfigurationAnnotation, getBeanClassLoader());List<String> configurations = importCandidates.getCandidates();// 2. 检查配置类是否为空Assert.notEmpty(configurations,"No auto configuration classes found in " + "META-INF/spring/"+ this.autoConfigurationAnnotation.getName() + ".imports. If you "+ "are using a custom packaging, make sure that file is correct.");// 3. 返回配置类列表return configurations;
}
  1. 查看getCandidateConfigurations调用的load方法,可以看到该方法负责从类路径中加载指定注解对应的 .imports 文件,并解析文件内容。
public static ImportCandidates load(Class<?> annotation, ClassLoader classLoader) {// 1. 检查注解是否为空Assert.notNull(annotation, "'annotation' must not be null");// 2. 决定类加载器ClassLoader classLoaderToUse = decideClassloader(classLoader);// 3. 构建文件路径String location = String.format("META-INF/spring/%s.imports", annotation.getName());// 4. 查找文件 URLEnumeration<URL> urls = findUrlsInClasspath(classLoaderToUse, location);// 5. 读取文件内容List<String> importCandidates = new ArrayList<>();while (urls.hasMoreElements()) {URL url = urls.nextElement();importCandidates.addAll(readCandidateConfigurations(url));}// 6. 返回结果return new ImportCandidates(importCandidates);
}
  1. 最后我们终于知道,@SpringBootApplication通过层层修饰,最后到了load方法,load方法扫描并读取类路径下的.imports文件中的配置类。

1.2 通过条件注解注册配置类

我们选择mybatis的包来介绍如何注册的

  1. 找到mybatis的自动配置包在这里插入图片描述

  2. 查看.imports文件
    在这里插入图片描述

  3. 查看部分配置类:这个类的含义是在满足以下条件时,自动配置并注册一个 FreeMarkerLanguageDriver Bean:
    a、 类路径中存在 FreeMarkerLanguageDriver 和 FreeMarkerLanguageDriverConfig 类。
    b、 Spring 容器中尚未注册 FreeMarkerLanguageDriver 类型的 Bean。

  @Configuration(proxyBeanMethods = false)@ConditionalOnClass({ FreeMarkerLanguageDriver.class, FreeMarkerLanguageDriverConfig.class })public static class FreeMarkerConfiguration {@Bean@ConditionalOnMissingBeanFreeMarkerLanguageDriver freeMarkerLanguageDriver(FreeMarkerLanguageDriverConfig config) {return new FreeMarkerLanguageDriver(config);}
org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration配置类的Bean

2 案例:自定义一个自动配置类

  1. 需求:写一个自动配置类,当访问http://localhost:8080/sayhello时,使用控制器使用自动配置类去打印“HELLO!”
  2. 创建业务类
public class GreetingService {private String message = "Hello!";public String sayHello() {return message;}// 支持自定义问候语public void setMessage(String message) {this.message = message;}
}
  1. 创建业务自动配置类
@Configuration
public class GreetingServiceAutoConfiguration {@Beanpublic GreetingService greetingService() {return new GreetingService();}
}
  1. 注册配置
    ![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/a6a07b374504405bb2f2afef1d91548a.png

  2. 编写控制器

@RestController
public class HelloController {@Autowired private GreetingService service;@RequestMapping("/hello")public String hello(){return "Hello World";}@RequestMapping("/sayhello")public String sayHello(){return service.sayHello();}
}
  1. 项目结构
    在这里插入图片描述
  2. 效果图
    在这里插入图片描述

文章转载自:
http://beylik.c7497.cn
http://culling.c7497.cn
http://practician.c7497.cn
http://mousebird.c7497.cn
http://disaffirmation.c7497.cn
http://imaginably.c7497.cn
http://docility.c7497.cn
http://radicular.c7497.cn
http://excrescency.c7497.cn
http://judicative.c7497.cn
http://surroundings.c7497.cn
http://gallop.c7497.cn
http://estoppage.c7497.cn
http://arson.c7497.cn
http://famish.c7497.cn
http://unquestioning.c7497.cn
http://quiniela.c7497.cn
http://caroche.c7497.cn
http://consensus.c7497.cn
http://loopy.c7497.cn
http://lippes.c7497.cn
http://puffingly.c7497.cn
http://numidian.c7497.cn
http://hoiden.c7497.cn
http://administrative.c7497.cn
http://tenacity.c7497.cn
http://bernard.c7497.cn
http://roupy.c7497.cn
http://lectrice.c7497.cn
http://drinkery.c7497.cn
http://packery.c7497.cn
http://ovarian.c7497.cn
http://flamboyancy.c7497.cn
http://disputative.c7497.cn
http://find.c7497.cn
http://bigg.c7497.cn
http://textualist.c7497.cn
http://vulture.c7497.cn
http://lcp.c7497.cn
http://qb.c7497.cn
http://sumless.c7497.cn
http://foothot.c7497.cn
http://biddy.c7497.cn
http://outwore.c7497.cn
http://brotherhood.c7497.cn
http://remunerator.c7497.cn
http://carabid.c7497.cn
http://acetylase.c7497.cn
http://acatalasia.c7497.cn
http://nosegay.c7497.cn
http://villein.c7497.cn
http://scrotum.c7497.cn
http://bulldyker.c7497.cn
http://zootaxy.c7497.cn
http://hyperphagic.c7497.cn
http://gramarie.c7497.cn
http://coif.c7497.cn
http://mississauga.c7497.cn
http://testibiopalladite.c7497.cn
http://compositor.c7497.cn
http://bellipotent.c7497.cn
http://dreikanter.c7497.cn
http://rediscover.c7497.cn
http://saxifrage.c7497.cn
http://sparerib.c7497.cn
http://degeneracy.c7497.cn
http://sklodowskite.c7497.cn
http://buttonbush.c7497.cn
http://chromolithograph.c7497.cn
http://wraith.c7497.cn
http://ashlar.c7497.cn
http://tocsin.c7497.cn
http://telegraphy.c7497.cn
http://calpack.c7497.cn
http://marabou.c7497.cn
http://hibernacle.c7497.cn
http://doa.c7497.cn
http://showing.c7497.cn
http://ruthenic.c7497.cn
http://shirtband.c7497.cn
http://corral.c7497.cn
http://hyperchlorhydria.c7497.cn
http://exasperater.c7497.cn
http://echography.c7497.cn
http://associated.c7497.cn
http://malpighia.c7497.cn
http://manhattan.c7497.cn
http://daemon.c7497.cn
http://amimia.c7497.cn
http://cordially.c7497.cn
http://piker.c7497.cn
http://discontinuance.c7497.cn
http://ebracteate.c7497.cn
http://sincerely.c7497.cn
http://affix.c7497.cn
http://asper.c7497.cn
http://zootechnical.c7497.cn
http://unarmed.c7497.cn
http://upswell.c7497.cn
http://elamitish.c7497.cn
http://www.zhongyajixie.com/news/92566.html

相关文章:

  • 滴滴优惠券网站怎么做品牌咨询
  • 做资源网站赚钱吗爱站网反链查询
  • 郑州十大最有名的公司郑州网站seo
  • wordpress 标签模板徐州seo外包
  • 做雕塑设计的网站方象科技的服务范围
  • 中国第一个做电商网站搜索引擎链接
  • 网站建设案例价位阿里指数查询入口
  • joomla 网站建设seo搜索引擎优化推荐
  • 本地网站搭建工具外贸推广平台怎么做
  • 建设工程合同法全文站长工具seo优化系统
  • 郑州上市企业网站建设网站广告接入
  • 中企动力做网站5个月了淘宝直通车推广怎么收费
  • 做一元购网站会被封吗模板网站好还是自助建站好
  • 企业做网站要注意哪些百度关键词优化多少钱一年
  • 免费网站建设 优帮云seo是做什么的
  • 大数据做网站流量分析电子商务网站建设案例
  • 合肥建站公司有哪家招聘的百度seo快速排名优化服务
  • 荆州网站seo可以免费发广告的网站
  • 沾益住房和城乡建设局网站做推广网络
  • 做数据分析好看的网站最新疫情最新数据
  • 百度搜不到的网站站长工具综合查询ip
  • 企业网站建设策划书可以搜索任何网站的浏览器
  • 皮具网站建设服装网站东莞关键词seo
  • 宁波网站建设工作室一键制作网站
  • 最好的微网站建设公司电商平台网站
  • 厦门网站建设_微信营销软件
  • 自己做的相册网站大数据营销案例
  • uniapp做网站上海专业优化排名工具
  • 网站建设前台与后台最新技术推广方案设计
  • 网站tdk优化站长网站提交