96SEO 2026-02-20 04:47 0
然后引入要自动注入的组件依赖然后现application.properties中加上相应配置就可以自动注入这个组件那么下面看看自动注入组件是如何实现的

Retention(RetentionPolicy.RUNTIME)
{AutoConfigurationExcludeFilter.class}
Retention(RetentionPolicy.RUNTIME)
Import({AutoConfigurationImportSelector.class})
spring.boot.enableautoconfiguration;Class?[]
}这个类又通过Import({AutoConfigurationImportSelector.class})
3、AutoConfigurationImportSelector这个bean查看这个bean
AutoConfigurationImportSelectorimplements
ResourceLoaderAware,BeanFactoryAware,
{}4、这个AutoConfigurationImportSelector类继承了DeferredImportSelector最终继承了ImportSelector重写这个类的selectImports方法可以快速导入一个bean查看selectImports方法
selectImports(AnnotationMetadata
(!isEnabled(annotationMetadata))
NO_IMPORTS;}AutoConfigurationMetadata
AutoConfigurationMetadataLoader.loadMetadata(this.beanClassLoader);AnnotationAttributes
getAttributes(annotationMetadata);ListString
getCandidateConfigurations(annotationMetadata,attributes);configurations
removeDuplicates(configurations);SetString
getExclusions(annotationMetadata,
attributes);checkExcludedClasses(configurations,
exclusions);configurations.removeAll(exclusions);configurations
autoConfigurationMetadata);fireAutoConfigurationImportEvents(configurations,
StringUtils.toStringArray(configurations);}5、查看ListString
getCandidateConfigurations(annotationMetadata,
getCandidateConfigurations(AnnotationMetadata
SpringFactoriesLoader.loadFactoryNames(getSpringFactoriesLoaderFactoryClass(),
getBeanClassLoader());Assert.notEmpty(configurations,No
configurations;}6、这个方法最终会调用loadSpringFactories方法这个方法把META-INF/spring.factories定义的类全部读到出来
org.springframework.boot.autoconfigure.EnableAutoConfiguration\
org.springframework.boot.autoconfigure.admin.SpringApplicationAdminJmxAutoConfiguration,\
org.springframework.boot.autoconfigure.aop.AopAutoConfiguration,\
org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration,\
org.springframework.boot.autoconfigure.batch.BatchAutoConfiguration,\private
(MultiValueMap)cache.get(classLoader);if
classLoader.getResources(META-INF/spring.factories)
ClassLoader.getSystemResources(META-INF/spring.factories);LinkedMultiValueMap
LinkedMultiValueMap();while(urls.hasMoreElements())
(URL)urls.nextElement();UrlResource
PropertiesLoaderUtils.loadProperties(resource);Iterator
properties.entrySet().iterator();while(var6.hasNext())
Arrays.asList(StringUtils.commaDelimitedListToStringArray((String)entry.getValue()));result.addAll((String)entry.getKey(),
factoryClassNames);}}cache.put(classLoader,
IllegalArgumentException(Unable
var9);}}}7、最终spring会根据这些组件中定义的注入条件将这些组件自动注入org.springframework.boot.autoconfigure下放了所有自动注入的组件以aop这个组件为例
Advice.class,这些class存在时才注入也就是说当引入相关依赖包时注入AnnotatedElement.class
Advice.class,AnnotatedElement.class
{ConfigurationEnableAspectJAutoProxy(proxyTargetClass
false)ConditionalOnProperty(prefix
JdkDynamicAutoProxyConfiguration
{}ConfigurationEnableAspectJAutoProxy(proxyTargetClass
true)ConditionalOnProperty(prefix
--dependencygroupIdorg.apache.tomcat.embed/groupIdartifactIdtomcat-embed-core/artifactIdversion8.5.16/version/dependency!--
--dependencygroupIdorg.apache.tomcat/groupIdartifactIdtomcat-jasper/artifactIdversion8.5.16/version/dependency/dependencies2、新建一个servlet文件
指定端口号tomcatServer.setPort(PORT);//
是否设置自动部署tomcatServer.getHost().setAutoDeploy(false);//
StandardContext();standardContex.setPath(CONTEX_PATH);//
监听上下文standardContex.addLifecycleListener(new
Tomcat.FixContextListener());//
tomcat容器添加standardContextomcatServer.getHost().addChild(standardContex);//
创建ServlettomcatServer.addServlet(CONTEX_PATH,
servleturl映射standardContex.addServletMappingDecoded(/index,
SERVLET_NAME);tomcatServer.start();System.out.println(tomcat服务器启动成功..);//
异步进行接收请求tomcatServer.getServer().await();}
http://localhost:8080/clock/index
boot在启动的时候启动一个tomcat实际上它启动的方式也是上面那么启动方式
tomcat也是一个组件那么它的引入方式也是通过spring.factories文件注入的
3、查看ServletWebServerFactoryAutoConfiguration这个类
ServletWebServerFactoryAutoConfiguration这个类用import快速导入了EmbeddedTomcat类
这个类注入了TomcatServletWebServerFactory这个bean
ConfigurationConditionalOnClass({
})ConditionalOnMissingBean(value
tomcatServletWebServerFactory()
TomcatServletWebServerFactory();}}4、查看TomcatServletWebServerFactory类
这个方法启动了一个tomcat那么这个方法是在哪个地方调用的可以在这个方法上打上断点查看它的调用链
getWebServer(ServletContextInitializer...
this.createTempDir(tomcat);tomcat.setBaseDir(baseDir.getAbsolutePath());Connector
Connector(this.protocol);tomcat.getService().addConnector(connector);this.customizeConnector(connector);tomcat.setConnector(connector);tomcat.getHost().setAutoDeploy(false);this.configureEngine(tomcat.getEngine());Iterator
this.additionalTomcatConnectors.iterator();while(var5.hasNext())
(Connector)var5.next();tomcat.getService().addConnector(additionalConnector);}this.prepareContext(tomcat.getHost(),
this.getTomcatWebServer(tomcat);}5、在getWebServer方法打断点然后启动spring
了一个SpringApplication对象然后执行了run方法
SpringApplication(primarySources)).run(args);}SpringApplication结构方法
SpringApplication(ResourceLoader
resourceLoader;Assert.notNull(primarySources,
null);//保存主类this.primarySources
LinkedHashSet(Arrays.asList(primarySources));//判断当前是什么类型项目this.webApplicationType
WebApplicationType.deduceFromClasspath();//从类路径下找到META-INF/spring.factories配置的所有ApplicationContextInitializersetInitializers((Collection)
getSpringFactoriesInstances(ApplicationContextInitializer.class));//从类路径下找到META-INF/spring.factories配置的所有ApplicationListenersetListeners((Collection)
getSpringFactoriesInstances(ApplicationListener.class));this.mainApplicationClass
StopWatch();stopWatch.start();ConfigurableApplicationContext
null;CollectionSpringBootExceptionReporter
ArrayList();configureHeadlessProperty();//从类路径下META‐INF/spring.factories取得SpringApplicationRunListenersSpringApplicationRunListeners
//回调所有的获取SpringApplicationRunListener.starting()方法listeners.starting();try
DefaultApplicationArguments(args);//准备环境ConfigurableEnvironment
prepareEnvironment(listeners,applicationArguments);configureIgnoreBeanInfo(environment);//创回调SpringApplicationRunListener.environmentPrepared()
printBanner(environment);//根据环境创建contextcontext
createApplicationContext();//错误的异常报表exceptionReporters
getSpringFactoriesInstances(SpringBootExceptionReporter.class,new
ConfigurableApplicationContext.class
context);//准备上下文环境;//将environment保存到ioc中//applyInitializers()调用所有的ApplicationContextInitializer的initialize方法
//调用所有的SpringApplicationRunListener的contextPrepared()prepareContext(context,
applicationArguments,printedBanner);
//SpringApplicationRunListener的contextLoaded
//扫描创建加载所有组件refreshContext(context);afterRefresh(context,
applicationArguments);stopWatch.stop();if
StartupInfoLogger(this.mainApplicationClass).logStarted(getApplicationLog(),
stopWatch);}//所有的SpringApplicationRunListener回调started方法listeners.started(context);//获取所有的ApplicationRunner和CommandLineRunner进行调用callRunners(context,
{//所有的SpringApplicationRunListener的running()listeners.running(context);}catch
IllegalStateException(ex);}return
boot内嵌的web容器是tomcat那么如果我们不想用tomcat
dependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactIdexclusionsexclusiongroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-tomcat/artifactId/exclusion/exclusions/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-undertow/artifactId/dependency/dependencies这个再启动spring
作为专业的SEO优化服务提供商,我们致力于通过科学、系统的搜索引擎优化策略,帮助企业在百度、Google等搜索引擎中获得更高的排名和流量。我们的服务涵盖网站结构优化、内容优化、技术SEO和链接建设等多个维度。
| 服务项目 | 基础套餐 | 标准套餐 | 高级定制 |
|---|---|---|---|
| 关键词优化数量 | 10-20个核心词 | 30-50个核心词+长尾词 | 80-150个全方位覆盖 |
| 内容优化 | 基础页面优化 | 全站内容优化+每月5篇原创 | 个性化内容策略+每月15篇原创 |
| 技术SEO | 基本技术检查 | 全面技术优化+移动适配 | 深度技术重构+性能优化 |
| 外链建设 | 每月5-10条 | 每月20-30条高质量外链 | 每月50+条多渠道外链 |
| 数据报告 | 月度基础报告 | 双周详细报告+分析 | 每周深度报告+策略调整 |
| 效果保障 | 3-6个月见效 | 2-4个月见效 | 1-3个月快速见效 |
我们的SEO优化服务遵循科学严谨的流程,确保每一步都基于数据分析和行业最佳实践:
全面检测网站技术问题、内容质量、竞争对手情况,制定个性化优化方案。
基于用户搜索意图和商业目标,制定全面的关键词矩阵和布局策略。
解决网站技术问题,优化网站结构,提升页面速度和移动端体验。
创作高质量原创内容,优化现有页面,建立内容更新机制。
获取高质量外部链接,建立品牌在线影响力,提升网站权威度。
持续监控排名、流量和转化数据,根据效果调整优化策略。
基于我们服务的客户数据统计,平均优化效果如下:
我们坚信,真正的SEO优化不仅仅是追求排名,而是通过提供优质内容、优化用户体验、建立网站权威,最终实现可持续的业务增长。我们的目标是与客户建立长期合作关系,共同成长。
Demand feedback