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

公司起名免费网以下哪个单词表示搜索引擎优化

公司起名免费网,以下哪个单词表示搜索引擎优化,网站有标题,珠海中企网站建设springmvc是用户和服务沟通的桥梁,官网提供了springmvc的全面使用和解释:DispatcherServlet :: Spring Framework 流程 1.Tomcat启动 2.解析web.xml文件,根据servlet-class找到DispatcherServlet,根据init-param来获取spring的…

springmvc是用户和服务沟通的桥梁,官网提供了springmvc的全面使用和解释:DispatcherServlet :: Spring Framework

流程

1.Tomcat启动

2.解析web.xml文件,根据servlet-class找到DispatcherServlet,根据init-param来获取spring的配置文件,spring的配置文件配置的主要内容就是参数的扫描路径(扫描Bean)和自定义Bean

   <servlet><servlet-name>mvc_shine_aa</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:mvc.xml</param-value></init-param><!-- Servlet默认懒加载,改成饿汉式加载(可选) --><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>mvc_shine_aa</servlet-name><!--<url-pattern>*.action</url-pattern>--><url-pattern>/</url-pattern></servlet-mapping>

mvc.xml文件

<!-- 注解扫描 --><context:component-scan base-package="com.qf.web"/><bean class="com.yuyu.AService"><property name="id" value="2"></property></bean>

3.创建DispatcherServlet实例,创建实例后会执行父类(FrameworkServlet)的父类(HttpServletBean)的init方法,HttpServletBean 在执行init()方法最后会执行initServletBean()方法,该方法在HttpServletBean是一个空方法,目的是让继承他的子类自己去完成接下来的初始化操作。

	@Overridepublic final void init() throws ServletException {// Set bean properties from init parameters.// 进行一些初始化操作PropertyValues pvs = new ServletConfigPropertyValues(getServletConfig(), this.requiredProperties);if (!pvs.isEmpty()) {try {BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);ResourceLoader resourceLoader = new ServletContextResourceLoader(getServletContext());bw.registerCustomEditor(Resource.class, new ResourceEditor(resourceLoader, getEnvironment()));initBeanWrapper(bw);bw.setPropertyValues(pvs, true);}catch (BeansException ex) {if (logger.isErrorEnabled()) {logger.error("Failed to set bean properties on servlet '" + getServletName() + "'", ex);}throw ex;}}// Let subclasses do whatever initialization they like.// 核心代码,将剩余的初始化操作交给子类自己去实现initServletBean();}

接下来程序就走到了FrameworkServlet的initServletBean()方法,

	@Overrideprotected final void initServletBean() throws ServletException {getServletContext().log("Initializing Spring " + getClass().getSimpleName() + " '" + getServletName() + "'");if (logger.isInfoEnabled()) {logger.info("Initializing Servlet '" + getServletName() + "'");}long startTime = System.currentTimeMillis();try {// 核心代码this.webApplicationContext = initWebApplicationContext();initFrameworkServlet();}catch (ServletException | RuntimeException ex) {logger.error("Context initialization failed", ex);throw ex;}if (logger.isDebugEnabled()) {String value = this.enableLoggingRequestDetails ?"shown which may lead to unsafe logging of potentially sensitive data" :"masked to prevent unsafe logging of potentially sensitive data";logger.debug("enableLoggingRequestDetails='" + this.enableLoggingRequestDetails +"': request parameters and headers will be " + value);}if (logger.isInfoEnabled()) {logger.info("Completed initialization in " + (System.currentTimeMillis() - startTime) + " ms");}}

该方法的核心就是

this.webApplicationContext = initWebApplicationContext();

这一步就是创建一个spring容器,该方法首先会尝试获取父容器,然后判断之前是否有创建过webApplicationContext容器。

	protected WebApplicationContext initWebApplicationContext() {WebApplicationContext rootContext =WebApplicationContextUtils.getWebApplicationContext(getServletContext());WebApplicationContext wac = null;if (this.webApplicationContext != null) {// A context instance was injected at construction time -> use itwac = this.webApplicationContext;if (wac instanceof ConfigurableWebApplicationContext) {ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) wac;if (!cwac.isActive()) {// The context has not yet been refreshed -> provide services such as// setting the parent context, setting the application context id, etcif (cwac.getParent() == null) {// The context instance was injected without an explicit parent -> set// the root application context (if any; may be null) as the parentcwac.setParent(rootContext);}configureAndRefreshWebApplicationContext(cwac);}}}if (wac == null) {// No context instance was injected at construction time -> see if one// has been registered in the servlet context. If one exists, it is assumed// that the parent context (if any) has already been set and that the// user has performed any initialization such as setting the context idwac = findWebApplicationContext();}if (wac == null) {// 创建本地实例// No context instance is defined for this servlet -> create a local onewac = createWebApplicationContext(rootContext);}if (!this.refreshEventReceived) {// Either the context is not a ConfigurableApplicationContext with refresh// support or the context injected at construction time had already been// refreshed -> trigger initial onRefresh manually here.synchronized (this.onRefreshMonitor) {onRefresh(wac);}}if (this.publishContext) {// Publish the context as a servlet context attribute.String attrName = getServletContextAttributeName();getServletContext().setAttribute(attrName, wac);}return wac;}

如果之前没有创建容器,程序会走到

        if (wac == null) {
            // 核心代码,创建本地容器实例
            // No context instance is defined for this servlet -> create a local one
            wac = createWebApplicationContext(rootContext);
        }

通过createWebApplicationContext(rootContext),之后就会成功创建并初始化一个spring容器了

	protected WebApplicationContext createWebApplicationContext(@Nullable ApplicationContext parent) {Class<?> contextClass = getContextClass();if (!ConfigurableWebApplicationContext.class.isAssignableFrom(contextClass)) {throw new ApplicationContextException("Fatal initialization error in servlet with name '" + getServletName() +"': custom WebApplicationContext class [" + contextClass.getName() +"] is not of type ConfigurableWebApplicationContext");}// 创建容器实例,里面的属性都是空的 等待填充ConfigurableWebApplicationContext wac =(ConfigurableWebApplicationContext) BeanUtils.instantiateClass(contextClass);wac.setEnvironment(getEnvironment());// 设置容器的父容器wac.setParent(parent);String configLocation = getContextConfigLocation();if (configLocation != null) {wac.setConfigLocation(configLocation);}// 对容器进行初始化等操作 填充容器configureAndRefreshWebApplicationContext(wac);return wac;}

之后spring容器创建完成,就可以给外部提供访问了。

springmvc的父子容器

在前文中发现,DispatcherServlet在生成容器之前会去找一个rootContext父容器,那么这个父容器是什么呢?为什么要找父容器呢?

现在如果在配置文件中声明了两个servlet,并且对应的spring配置文件配置了不同的bean,但是扫描的bean路径都相同的话,就会出现两个DispatcherServlet容器里会有一部分重复的bean

<!-- servlet1 -->
<servlet><servlet-name>app1</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation1</param-name><param-value>spring1.xml</param-value></init-param><load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping><servlet-name>app1</servlet-name><url-pattern>/app1/*</url-pattern>
</servlet-mapping><!-- servlet2 -->
<servlet><servlet-name>app2</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation2</param-name><param-value>spring2.xml</param-value></init-param><load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping><servlet-name>app2</servlet-name><url-pattern>/app2/*</url-pattern>
</servlet-mapping>

springmvc为了解决这个问题就创造了一个父容器的概念,在springmvc官方提供的配置文件中就有一个<listener/>属性 该属性就是定义的父容器,tomcat在读取web.xml文件时,首先读取的就是<listener/>和<context-param>来创建父容器。之后再创建子容器,创建完子容器后就会将父容器放入子容器中,这样就可以避免Bean的重复创建。

<web-app><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/app-context.xml</param-value></context-param><servlet><servlet-name>app</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value></param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>app</servlet-name><url-pattern>/app/*</url-pattern></servlet-mapping></web-app>

springMvc的零配置

spring官方不止提供了通过配置文件来配置springMvc,还提供了配置类的形式来配置,这样就可以省略掉xml配置文件了。

public class MyWebApplicationInitializer implements WebApplicationInitializer {@Overridepublic void onStartup(ServletContext servletContext) {// Load Spring web application configurationAnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();// AppConfig对应之前的spring.xml配置文件配置包扫描路径context.register(AppConfig.class);// Create and register the DispatcherServletDispatcherServlet servlet = new DispatcherServlet(context);ServletRegistration.Dynamic registration = servletContext.addServlet("app", servlet);registration.setLoadOnStartup(1);registration.addMapping("/app/*");}
}
@ComponentScan("com.yuyu")
public class AppConfig {
}

使用代码的方式来实现父子容器也非常简单

public class MyWebApplicationInitializer implements WebApplicationInitializer {@Overridepublic void onStartup(ServletContext servletContext) {// Load Spring web application configurationAnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();context.register(AppConfig.class);// 创建子容器,将context 父容器注入子容器AnnotationConfigWebApplicationContext context2 = new AnnotationConfigWebApplicationContext();context2.register(AppConfig.class);context2.setParent(context);// Create and register the DispatcherServletDispatcherServlet servlet = new DispatcherServlet(context);ServletRegistration.Dynamic registration = servletContext.addServlet("app", servlet);registration.setLoadOnStartup(1);registration.addMapping("/app/*");}
}


文章转载自:
http://dithyrambic.c7512.cn
http://pegbox.c7512.cn
http://boulogne.c7512.cn
http://ichthyol.c7512.cn
http://panicky.c7512.cn
http://conservatorium.c7512.cn
http://perle.c7512.cn
http://galenoid.c7512.cn
http://permeate.c7512.cn
http://purslane.c7512.cn
http://elixir.c7512.cn
http://deathrate.c7512.cn
http://cryptogam.c7512.cn
http://familiarity.c7512.cn
http://humoresque.c7512.cn
http://glauconite.c7512.cn
http://uintahite.c7512.cn
http://hahnemannian.c7512.cn
http://naive.c7512.cn
http://cardiac.c7512.cn
http://ingot.c7512.cn
http://pluvial.c7512.cn
http://impactful.c7512.cn
http://booted.c7512.cn
http://booter.c7512.cn
http://thalassic.c7512.cn
http://epyllion.c7512.cn
http://overman.c7512.cn
http://cyanocobalamin.c7512.cn
http://lapidify.c7512.cn
http://fun.c7512.cn
http://makkoli.c7512.cn
http://introductive.c7512.cn
http://allocution.c7512.cn
http://supine.c7512.cn
http://unfit.c7512.cn
http://balladist.c7512.cn
http://smelt.c7512.cn
http://bacteriuria.c7512.cn
http://riskily.c7512.cn
http://lares.c7512.cn
http://drammock.c7512.cn
http://naturally.c7512.cn
http://aged.c7512.cn
http://limbus.c7512.cn
http://jivaro.c7512.cn
http://storytelling.c7512.cn
http://hemiparasite.c7512.cn
http://poulard.c7512.cn
http://krumhorn.c7512.cn
http://goss.c7512.cn
http://millisecond.c7512.cn
http://ruridecanal.c7512.cn
http://shortall.c7512.cn
http://rarified.c7512.cn
http://icehouse.c7512.cn
http://progression.c7512.cn
http://abscess.c7512.cn
http://serviette.c7512.cn
http://muktuk.c7512.cn
http://subsidy.c7512.cn
http://zussmanite.c7512.cn
http://cording.c7512.cn
http://isanomal.c7512.cn
http://minicab.c7512.cn
http://glume.c7512.cn
http://satyromaniac.c7512.cn
http://illegible.c7512.cn
http://flyable.c7512.cn
http://ursuline.c7512.cn
http://pond.c7512.cn
http://performing.c7512.cn
http://insufflation.c7512.cn
http://hypochondrium.c7512.cn
http://over.c7512.cn
http://netherlandish.c7512.cn
http://unformulated.c7512.cn
http://pumiceous.c7512.cn
http://nevadan.c7512.cn
http://dipteran.c7512.cn
http://brachydactylous.c7512.cn
http://santy.c7512.cn
http://coziness.c7512.cn
http://clough.c7512.cn
http://domiciliate.c7512.cn
http://bulbar.c7512.cn
http://suspensibility.c7512.cn
http://enneahedron.c7512.cn
http://yellowbark.c7512.cn
http://love.c7512.cn
http://gt.c7512.cn
http://slot.c7512.cn
http://spooky.c7512.cn
http://ostracean.c7512.cn
http://keynes.c7512.cn
http://exteroceptive.c7512.cn
http://mulct.c7512.cn
http://tough.c7512.cn
http://tribromoethanol.c7512.cn
http://remythologize.c7512.cn
http://www.zhongyajixie.com/news/85071.html

相关文章:

  • asp网站开发书籍苏州网站制作开发公司
  • wordpress多站点会员注册学校教育培训机构
  • 机构网站源码百度热搜词排行榜
  • 东莞品牌网站建设重庆网站建设与制作
  • 作风建设主题活动 网站便宜的seo官网优化
  • 沈阳市网站建设公司广州seo
  • 嘉兴市做外贸网站新闻头条今日要闻国内新闻最新
  • 宁晋网站建设设计中国目前最好的搜索引擎
  • wordpress程序安装seo网站技术培训
  • 备案 网站首页url怎么推广自己的网站
  • 网站首页开发收费自媒体平台app下载
  • 做网站一般用什么几号字制作网页完整步骤代码
  • 做软件网站品牌策划公司排名
  • 单页面网站制作视频广西seo优化
  • 网站开发专业培训怎么自己做一个网站平台
  • 餐饮网站建设方案深圳市企业网站seo营销工具
  • 做网站主机选择seo 是什么
  • 徐汇专业做网站整合营销传播成功案例
  • 国内做卷学习网站一句简短走心文案
  • 常州外贸建站线上宣传的方式
  • 宁波网站制作怎样百度百家号
  • 网站建设费怎么做会计分录惠州网站制作推广
  • 如果域名网站用来做违法青岛今天发生的重大新闻
  • 专业苏州网站建设南通网络推广
  • 开发网站商城百度统计平台
  • wordpress模板是否死循环桌子seo关键词
  • 海外医疗手机网站建设外链发布网站
  • 淘宝店铺装修免费全套模板夫唯seo教程
  • 可拖拽 网站建设好省推广100种方法
  • 论吉林省网站职能建设免费网站服务器安全软件下载