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

宁波网站建设公司哪有百度seo教程视频

宁波网站建设公司哪有,百度seo教程视频,上海武汉阳网站建设,电子商务公司是做什么的目录 代码入口上下文容器 加载web容器WebServercreateWebServergetWebServerFactory():getWebServer(): 执行WebServer#start自动配置读取配置修改配置 代码入口 上下文容器 SpringApplication.run(App.class); //追踪下去发现 context createApplicationContext…

目录

    • 代码入口
      • 上下文容器
    • 加载web容器
      • WebServer
      • createWebServer
      • getWebServerFactory():
      • getWebServer():
    • 执行WebServer#start
    • 自动配置
      • 读取配置
      • 修改配置

代码入口

上下文容器

SpringApplication.run(App.class);
//追踪下去发现
context = createApplicationContext();createApplicationContext()return this.applicationContextFactory.create(this.webApplicationType);这里用了策略模式:
读取 interface org.springframework.boot.ApplicationContextFactory 的实现
根据 webApplicationType 匹配对应的处理
case : WebApplicationType.REACTIVE : return new AnnotationConfigReactiveWebServerApplicationContext();
case : WebApplicationType.SERVLET : return new AnnotationConfigServletWebServerApplicationContext();然后就创建了:
org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext

webApplicationType 获取

//this.webApplicationType是在new SpringApplication()的时候赋值的
this.webApplicationType = WebApplicationType.deduceFromClasspath();WebApplicationType.deduceFromClasspath():if (classpath中 有 org.springframework.web.reactive.DispatcherHandler 
且 没有 org.springframework.web.servlet.DispatcherServlet 
且 没有 org.glassfish.jersey.servlet.ServletContainer) {return WebApplicationType.REACTIVE;
}//有 spring-web的依赖则有
if (classpath中 没有 javax.servlet.Servlet) {return WebApplicationType.NONE;
}
if (classpath中 没有 org.springframework.web.context.ConfigurableWebApplicationContext) {return WebApplicationType.NONE;
}
return WebApplicationType.SERVLET;

加载web容器

首先我们知道了现在的上下文是AnnotationConfigServletWebServerApplicationContext
看一下依赖
在这里插入图片描述

执行 org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext#onRefreshorg.springframework.boot.web.servlet.context.ServletWebServerApplicationContext#createWebServer
来创建一个WebServer

WebServer

我们先来分析下这个类
这个类是一个接口

void start() throws WebServerException;
void stop() throws WebServerException;
//返回监听端口
int getPort();
//优雅关闭
void shutDownGracefully(GracefulShutdownCallback callback);

createWebServer

//看下容器中是否有webServer 这里是没有的
WebServer webServer = this.webServer;
ServletContext servletContext = this.servletContext;
if (webServer == null && servletContext == null) {//获取WebServerFactory 这里会确定 web容器是 tomcat 还是其他ServletWebServerFactory factory = getWebServerFactory();//这一步就初始化容器了 设置端口啥的//这里要注意了 getWebServer入参是ServletContextInitializer 这是一个函数类//也就是说只是设置了行为而不需要执行 先执行了getWebServerthis.webServer = factory.getWebServer(getSelfInitializer());//注册优雅关闭getBeanFactory().registerSingleton("webServerGracefulShutdown",new WebServerGracefulShutdownLifecycle(this.webServer));//注册启动 关闭getBeanFactory().registerSingleton("webServerStartStop",new WebServerStartStopLifecycle(this, this.webServer));
}

getWebServerFactory():

//获取Bean工厂里ServletWebServerFactory的BeanName
//这里获取的是 tomcatServletWebServerFactory
String[] beanNames = getBeanFactory().getBeanNamesForType(ServletWebServerFactory.class);
//这里会校验 容器中有且只能有一个ServletWebServerFactory类
if (beanNames.length == 0) {throw new MissingWebServerFactoryBeanException()}
if (beanNames.length > 1) {throw new ApplicationContextException()}
return getBeanFactory().getBean(beanNames[0], ServletWebServerFactory.class);

为什么获取的是 tomcatServletWebServerFactory 呢?

一般找不到在哪里注入的Bean的时候就可以试一下搜索XXXAutoConfiguration
就是利用自动配置类 SPI机制加载 ServletWebServerFactoryAutoConfiguration
其中引入了 
ServletWebServerFactoryConfiguration.EmbeddedTomcat.class
ServletWebServerFactoryConfiguration.EmbeddedJetty.class
ServletWebServerFactoryConfiguration.EmbeddedUndertow.class
但是这三个类都有各自创建的条件比如tomcat@Configuration(proxyBeanMethods = false)
// 这三个类在 类加载器里都存在
@ConditionalOnClass({ Servlet.class, Tomcat.class, UpgradeProtocol.class })
//要是有用户自定义的 ServletWebServerFactory 类型的Bean就不创建
@ConditionalOnMissingBean(value = ServletWebServerFactory.class, search = SearchStrategy.CURRENT)
static class EmbeddedTomcat {//这里的ObjectProvider 意思就是有了就设置进去,没了设置一个内容为空的对象//给对Tomcat进行自定义设置的一个扩展,再配置无法满足需求的时候@BeanTomcatServletWebServerFactory tomcatServletWebServerFactory(ObjectProvider<TomcatConnectorCustomizer> connectorCustomizers,ObjectProvider<TomcatContextCustomizer> contextCustomizers,ObjectProvider<TomcatProtocolHandlerCustomizer<?>> protocolHandlerCustomizers) {TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();factory.getTomcatConnectorCustomizers().addAll(connectorCustomizers.orderedStream().collect(Collectors.toList()));factory.getTomcatContextCustomizers().addAll(contextCustomizers.orderedStream().collect(Collectors.toList()));factory.getTomcatProtocolHandlerCustomizers().addAll(protocolHandlerCustomizers.orderedStream().collect(Collectors.toList()));return factory;}
}

注意
@ConditionalOnClass({ Servlet.class, Tomcat.class, UpgradeProtocol.class })
这个注解里依赖的 class即使不存在也没关系 因为编译运行都不会报错
因为本来我们应用里依赖的就是 jar包
jar包就是编译好的class文件,所以不会再重复编译了
运行的时候也不是直接反射,而是利用ASM技术直接读的字节码获取引用类的全类名
然后调用类加载器加载,加载不到就是没有

getWebServer():

Tomcat tomcat = new Tomcat();
然后进行各种设置 下面三个日志就是这一步打印的
o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
o.apache.catalina.core.StandardService   : Starting service [Tomcat]
org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.71]总之就是创建了服务 但是没有真正的启动因为关系是这样的 上下文的refresh()方法中
// Initialize other special beans in specific context subclasses.
// 此时还在这里
onRefresh();// Check for listener beans and register them.
registerListeners();// Instantiate all remaining (non-lazy-init) singletons.
// 创建 非懒加载的单例bean
finishBeanFactoryInitialization(beanFactory);// Last step: publish corresponding event.
// 最后一步 到这里 所有Bean都已经ok了 可以提供服务出来了
finishRefresh();

执行WebServer#start

finishRefresh()getLifecycleProcessor().onRefresh() 中的 onRefresh()
onRefresh()startBeans(true);startBeans(true) :
获取beanFactory 中所有的 Lifecycle.class 类型的Bean 设置到 Map<String, Lifecycle> lifecycleBeansMap<Integer, LifecycleGroup> phases = new TreeMap<>();
遍历 lifecycleBeans : (beanName, bean){if (bean instanceof SmartLifecycle && bean.isAutoStartup())) {int phase = getPhase(bean);//这个就是说如果map的value已存在 那么就add(beanName, bean)//不存在就创建phases.computeIfAbsent(phase,p -> new LifecycleGroup(phase, this.timeoutPerShutdownPhase, lifecycleBeans, autoStartupOnly)).add(beanName, bean);if (!phases.isEmpty()) {//这里就执行了 bean.start();//也就是日志:o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''phases.values().forEach(LifecycleGroup::start);}}
}

自动配置

我们经常用的比如改端口

server.prot=8080

是怎么实现的呢?

读取配置

//这个注释意思是如果这个类没有加载 那么ServerProperties这个类也不需要加载了
@EnableConfigurationProperties(ServerProperties.class)
public class ServletWebServerFactoryAutoConfiguration {}@ConfigurationProperties(prefix = "server", ignoreUnknownFields = true)
public class ServerProperties {private Integer port;...
}

这里就是读取配置
那再哪里修改的呢

修改配置

@Import({ ServletWebServerFactoryAutoConfiguration.BeanPostProcessorsRegistrar.class,...}
public class ServletWebServerFactoryAutoConfiguration {}BeanPostProcessorsRegistrar 在 registerBeanDefinitions 方法中注册了WebServerFactoryCustomizerBeanPostProcessorWebServerFactoryCustomizerBeanPostProcessor 的 postProcessBeforeInitialization 方法中遍历所有 WebServerFactoryCustomizer.class 类的Bean : customizer {customizer.customize(webServerFactory);
}

哪里注册了 WebServerFactoryCustomizer ?

public class ServletWebServerFactoryAutoConfiguration {@Beanpublic ServletWebServerFactoryCustomizer servletWebServerFactoryCustomizer(ServerProperties serverProperties){...}...
}org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryCustomizer#customize 中@Override
public void customize(ConfigurableServletWebServerFactory factory) {PropertyMapper map = PropertyMapper.get().alwaysApplyingWhenNonNull();//存在配置 则调用setPortmap.from(this.serverProperties::getPort).to(factory::setPort);map.from(this.serverProperties::getAddress).to(factory::setAddress);...
}也就是调用了ConfigurableServletWebServerFactory 的setPort

最终读取

org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory#getWebServer 中
Tomcat tomcat = new Tomcat();
...
Connector connector = new Connector(this.protocol);
...
customizeConnector(connector);其中customizeConnector(connector)int port = Math.max(getPort(), 0);
connector.setPort(port);其中getPort():
获取属性port 默认是 8080

文章转载自:
http://dinncoknuckleball.bpmz.cn
http://dinncosalvo.bpmz.cn
http://dinncodustbin.bpmz.cn
http://dinncohippomenes.bpmz.cn
http://dinncosensibly.bpmz.cn
http://dinncolycine.bpmz.cn
http://dinncopair.bpmz.cn
http://dinncohalluces.bpmz.cn
http://dinncoboudicca.bpmz.cn
http://dinncobodgie.bpmz.cn
http://dinncoencipher.bpmz.cn
http://dinncofordless.bpmz.cn
http://dinncoanthropophobia.bpmz.cn
http://dinncochoybalsan.bpmz.cn
http://dinncopander.bpmz.cn
http://dinncokiltie.bpmz.cn
http://dinncolite.bpmz.cn
http://dinncobeachy.bpmz.cn
http://dinncoandes.bpmz.cn
http://dinncothanage.bpmz.cn
http://dinncoembryotrophe.bpmz.cn
http://dinncosubtractive.bpmz.cn
http://dinncoshanghai.bpmz.cn
http://dinncophosphureted.bpmz.cn
http://dinncobat.bpmz.cn
http://dinncopalatinate.bpmz.cn
http://dinncotakeoff.bpmz.cn
http://dinncocarpale.bpmz.cn
http://dinncorip.bpmz.cn
http://dinncoho.bpmz.cn
http://dinncolithographic.bpmz.cn
http://dinncounbroke.bpmz.cn
http://dinncoipsilateral.bpmz.cn
http://dinncocrystallization.bpmz.cn
http://dinncofuneral.bpmz.cn
http://dinncofoveolate.bpmz.cn
http://dinncothyrse.bpmz.cn
http://dinncospirea.bpmz.cn
http://dinncoultramontane.bpmz.cn
http://dinncoasc.bpmz.cn
http://dinnconoachian.bpmz.cn
http://dinncosyphilous.bpmz.cn
http://dinncozymase.bpmz.cn
http://dinncoriia.bpmz.cn
http://dinncoeasterner.bpmz.cn
http://dinncochorion.bpmz.cn
http://dinncotwelvemonth.bpmz.cn
http://dinnconagual.bpmz.cn
http://dinncobatiste.bpmz.cn
http://dinncounprotestantize.bpmz.cn
http://dinncoimpedient.bpmz.cn
http://dinncopresswoman.bpmz.cn
http://dinncovertex.bpmz.cn
http://dinncopfda.bpmz.cn
http://dinncolibertinage.bpmz.cn
http://dinncoscye.bpmz.cn
http://dinncosunback.bpmz.cn
http://dinncohistogenesis.bpmz.cn
http://dinnconautical.bpmz.cn
http://dinncochrysalides.bpmz.cn
http://dinncocellulitis.bpmz.cn
http://dinncovelocity.bpmz.cn
http://dinncofatherlike.bpmz.cn
http://dinncosudbury.bpmz.cn
http://dinncohsus.bpmz.cn
http://dinncocornetto.bpmz.cn
http://dinncoyamen.bpmz.cn
http://dinncovicariously.bpmz.cn
http://dinncohorizonless.bpmz.cn
http://dinncogosplan.bpmz.cn
http://dinncoedi.bpmz.cn
http://dinncophobia.bpmz.cn
http://dinnconatatorium.bpmz.cn
http://dinncodraconian.bpmz.cn
http://dinncojalalabad.bpmz.cn
http://dinncodevaluationist.bpmz.cn
http://dinncomario.bpmz.cn
http://dinncorockrose.bpmz.cn
http://dinncojukes.bpmz.cn
http://dinncoendostea.bpmz.cn
http://dinncoabstrusity.bpmz.cn
http://dinncoinnocency.bpmz.cn
http://dinncophytotoxin.bpmz.cn
http://dinncospeer.bpmz.cn
http://dinncoarbitress.bpmz.cn
http://dinncoxxxiv.bpmz.cn
http://dinncodataller.bpmz.cn
http://dinncodividers.bpmz.cn
http://dinncogovernance.bpmz.cn
http://dinncohaphtarah.bpmz.cn
http://dinncovews.bpmz.cn
http://dinncomedalet.bpmz.cn
http://dinncosalique.bpmz.cn
http://dinncopreachment.bpmz.cn
http://dinncoheave.bpmz.cn
http://dinncopostclassical.bpmz.cn
http://dinncowesterveldite.bpmz.cn
http://dinncocassab.bpmz.cn
http://dinncoimmedicable.bpmz.cn
http://dinncoresegmentation.bpmz.cn
http://www.dinnco.com/news/151660.html

相关文章:

  • 龙口做网站价格网络营销推广公司名称
  • 沧州企业网站制作独立网站和平台网站
  • 开源it运维管理软件网站优化排名提升
  • 成都广告制作公司杭州百度首页优化
  • 做的网站需要买什么服务器百度seo搜索引擎优化方案
  • 怎样利用网站做推广成都关键词优化报价
  • 网站建设是半年的持久战php免费开源crm系统
  • 什么软件做高级网站宁波seo网络推广渠道介绍
  • 建设企业网站成本多少钱推广普通话的宣传语
  • 手机网站制作价格郑州网站推广技术
  • 公司网站开发社群营销怎么做
  • 网站是什么字体色盲测试图片
  • office做网站的软件wordpress企业网站模板
  • 做批发比较好的网站有哪些seo网络培训学校
  • 莆田网站制作软件深圳seo
  • 重庆企业网站推广公司深圳百度关键字优化
  • 优秀的电商设计网站google优化排名
  • 电子商务网页制作试题及答案阜新网站seo
  • 判断网站做的好坏潍坊seo排名
  • wordpress 获取当前用户seo课程总结怎么写
  • 美容养生连锁东莞网站建设电子商务网站建设多少钱
  • 中企业网站建设影响关键词优化的因素
  • 阿里云轻量应用服务器wordpress济南seo官网优化
  • 外贸seo网站建站网站推广服务
  • 网页设计实训报告参考文献seo是什么平台
  • 网站建设广告网站建设加推广优化
  • 柳州网站建设源码seo平台是什么
  • 网站自动推广百度收录量
  • 在本地做的网站怎么修改域名软文推广范文
  • 直播网站开发技术电商的推广方式有哪些