spring boot中servlet启动原理

内置容器源码解析:DispatcherServlet加载过程 DispatcherServlet的加载过程 DispatcherServlet 的获取 还 记 得 在 上 一 章 Web应 用 中 自 动 配 置 的 DispatcherServlet 和 DispatcherServletRegistra-tionBean 吗?当时只是将其实例化了,并未做其他处理。而在上节 WebServer 初始化的过程中又加载了它们。下面我们进行相关源码的解析。 在 ServletWebServerApplicationContext#createWebServer 方 阅读详情

启动过程及原理

1 spring boot 应用启动运行run方法


StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        ConfigurableApplicationContext context = null;
        FailureAnalyzers analyzers = null;
        configureHeadlessProperty();
        SpringApplicationRunListeners listeners = getRunListeners(args);
        listeners.starting();
        try {
            ApplicationArguments applicationArguments = new DefaultApplicationArguments(
                    args);
            ConfigurableEnvironment environment = prepareEnvironment(listeners,
                    applicationArguments);
            Banner printedBanner = printBanner(environment);
                       //创建一个ApplicationContext容器
            context = createApplicationContext();
            analyzers = new FailureAnalyzers(context);
            prepareContext(context, environment, listeners, applicationArguments,
                    printedBanner);
                      //刷新IOC容器
            refreshContext(context);
            afterRefresh(context, applicationArguments);
            listeners.finished(context, null);
            stopWatch.stop();
            if (this.logStartupInfo) {
                new StartupInfoLogger(this.mainApplicationClass)
                        .logStarted(getApplicationLog(), stopWatch);
            }
            return context;
        }
        catch (Throwable ex) {
            handleRunFailure(context, listeners, analyzers, ex);
            throw new IllegalStateException(ex);
        }     

 

2  createApplicationContext():创建IOC容器,如果是web应用则创建AnnotationConfigEmbeddedWebApplacation的IOC容器,如果不是,则创建AnnotationConfigApplication的IOC容器


    public static final String DEFAULT_CONTEXT_CLASS = "org.springframework.context."
            + "annotation.AnnotationConfigApplicationContext";

    /**
     * The class name of application context that will be used by default for web
     * environments.
     */
    public static final String DEFAULT_WEB_CONTEXT_CLASS = "org.springframework."
            + "boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext";


protected ConfigurableApplicationContext createApplicationContext() {
        Class<?> contextClass = this.applicationContextClass;
        if (contextClass == null) {
            try {
          //根据应用环境,创建不同的IOC容器 contextClass
= Class.forName(this.webEnvironment ? DEFAULT_WEB_CONTEXT_CLASS : DEFAULT_CONTEXT_CLASS); } catch (ClassNotFoundException ex) { throw new IllegalStateException( "Unable create a default ApplicationContext, " + "please specify an ApplicationContextClass", ex); } } return (ConfigurableApplicationContext) BeanUtils.instantiate(contextClass); }

3    refreshContext(context) spring boot刷新IOC容器(创建容器对象,并初始化容器,创建容器每一个组件)


private void refreshContext(ConfigurableApplicationContext context) {
        refresh(context);
        if (this.registerShutdownHook) {
            try {
                context.registerShutdownHook();
            }
            catch (AccessControlException ex) {
                // Not allowed in some environments.
            }
        }
    }

4 refresh(context);刷新刚才创建的IOC容器

protected void refresh(ApplicationContext applicationContext) {
        Assert.isInstanceOf(AbstractApplicationContext.class, applicationContext);
        ((AbstractApplicationContext) applicationContext).refresh();
    }

5 调用父类的refresh()的方法


public void refresh() throws BeansException, IllegalStateException {
        Object var1 = this.startupShutdownMonitor;
        synchronized(this.startupShutdownMonitor) {
            this.prepareRefresh();
            ConfigurableListableBeanFactory beanFactory = this.obtainFreshBeanFactory();
            this.prepareBeanFactory(beanFactory);

            try {
                this.postProcessBeanFactory(beanFactory);
                this.invokeBeanFactoryPostProcessors(beanFactory);
                this.registerBeanPostProcessors(beanFactory);
                this.initMessageSource();
                this.initApplicationEventMulticaster();
                this.onRefresh();
                this.registerListeners();
                this.finishBeanFactoryInitialization(beanFactory);
                this.finishRefresh();
            } catch (BeansException var9) {
                if (this.logger.isWarnEnabled()) {
                    this.logger.warn("Exception encountered during context initialization - cancelling refresh attempt: " + var9);
                }

                this.destroyBeans();
                this.cancelRefresh(var9);
                throw var9;
            } finally {
                this.resetCommonCaches();
            }

        }
    }

6  抽象父类AbstractApplicationContext类的子类EmbeddedWebApplicationContext的onRefresh方法


@Override
    protected void onRefresh() {
        super.onRefresh();
        try {
            createEmbeddedServletContainer();
        }
        catch (Throwable ex) {
            throw new ApplicationContextException("Unable to start embedded container",
                    ex);
        }
    }

7  在createEmbeddedServletContainer放啊发中会获取嵌入式Servlet容器工厂,由容器工厂创建Servlet


private void createEmbeddedServletContainer() {
        EmbeddedServletContainer localContainer = this.embeddedServletContainer;
        ServletContext localServletContext = getServletContext();
        if (localContainer == null && localServletContext == null) {
                //获取嵌入式Servlet容器工厂 EmbeddedServletContainerFactory containerFactory
= getEmbeddedServletContainerFactory();
          //根据容器工厂获取对应嵌入式Servlet容器
this.embeddedServletContainer = containerFactory .getEmbeddedServletContainer(getSelfInitializer()); } else if (localServletContext != null) { try { getSelfInitializer().onStartup(localServletContext); } catch (ServletException ex) { throw new ApplicationContextException("Cannot initialize servlet context", ex); } } initPropertySources(); }

8  从IOC容器中获取Servlet容器工厂


//EmbeddedWebApplicationContext#getEmbeddedServletContainerFactory  
protected EmbeddedServletContainerFactory getEmbeddedServletContainerFactory() {  
    // Use bean names so that we don't consider the hierarchy  
    String[] beanNames = getBeanFactory()  
        .getBeanNamesForType(EmbeddedServletContainerFactory.class);  
    if (beanNames.length == 0) {  
        throw new ApplicationContextException(  
            "Unable to start EmbeddedWebApplicationContext due to missing "  
            + "EmbeddedServletContainerFactory bean.");  
    }  
    if (beanNames.length > 1) {  
        throw new ApplicationContextException(  
            "Unable to start EmbeddedWebApplicationContext due to multiple "  
            + "EmbeddedServletContainerFactory beans : "  
            + StringUtils.arrayToCommaDelimitedString(beanNames));  
    }  
    return getBeanFactory().getBean(beanNames[0],  
                                    EmbeddedServletContainerFactory.class);  
}  

 

9  使用Servlet容器工厂获取嵌入式Servlet容器,具体使用哪一个容器工厂看配置环境依赖

this.embeddedServletContainer = containerFactory  
            .getEmbeddedServletContainer(getSelfInitializer());  

10  上述创建过程  首先启动IOC容器,接着启动嵌入式Servlet容器,接着将IOC容器中剩下没有创建的对象获取出来,比如自己创建的controller

// Instantiate all remaining (non-lazy-init) singletons.
                finishBeanFactoryInitialization(beanFactory);

protected void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory) {
        // Initialize conversion service for this context.
        if (beanFactory.containsBean(CONVERSION_SERVICE_BEAN_NAME) &&
                beanFactory.isTypeMatch(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class)) {
            beanFactory.setConversionService(
                    beanFactory.getBean(CONVERSION_SERVICE_BEAN_NAME, ConversionService.class));
        }

        // Register a default embedded value resolver if no bean post-processor
        // (such as a PropertyPlaceholderConfigurer bean) registered any before:
        // at this point, primarily for resolution in annotation attribute values.
        if (!beanFactory.hasEmbeddedValueResolver()) {
            beanFactory.addEmbeddedValueResolver(new StringValueResolver() {
                @Override
                public String resolveStringValue(String strVal) {
                    return getEnvironment().resolvePlaceholders(strVal);
                }
            });
        }

        // Initialize LoadTimeWeaverAware beans early to allow for registering their transformers early.
        String[] weaverAwareNames = beanFactory.getBeanNamesForType(LoadTimeWeaverAware.class, false, false);
        for (String weaverAwareName : weaverAwareNames) {
            getBean(weaverAwareName);
        }

        // Stop using the temporary ClassLoader for type matching.
        beanFactory.setTempClassLoader(null);

        // Allow for caching all bean definition metadata, not expecting further changes.
        beanFactory.freezeConfiguration();

        // Instantiate all remaining (non-lazy-init) singletons.
        beanFactory.preInstantiateSingletons();
    }

 

看看 preInstantiateSingletons方法


public void preInstantiateSingletons() throws BeansException {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("Pre-instantiating singletons in " + this);
        }

        List<String> beanNames = new ArrayList(this.beanDefinitionNames);
        Iterator var2 = beanNames.iterator();

        while(true) {
            while(true) {
                String beanName;
                RootBeanDefinition bd;
                do {
                    do {
                        do {
                            if (!var2.hasNext()) {
                                var2 = beanNames.iterator();

                                while(var2.hasNext()) {
                                    beanName = (String)var2.next();
                                    Object singletonInstance = this.getSingleton(beanName);
                                    if (singletonInstance instanceof SmartInitializingSingleton) {
                                        final SmartInitializingSingleton smartSingleton = (SmartInitializingSingleton)singletonInstance;
                                        if (System.getSecurityManager() != null) {
                                            AccessController.doPrivileged(new PrivilegedAction<Object>() {
                                                public Object run() {
                                                    smartSingleton.afterSingletonsInstantiated();
                                                    return null;
                                                }
                                            }, this.getAccessControlContext());
                                        } else {
                                            smartSingleton.afterSingletonsInstantiated();
                                        }
                                    }
                                }

                                return;
                            }

                            beanName = (String)var2.next();
                            bd = this.getMergedLocalBeanDefinition(beanName);
                        } while(bd.isAbstract());
                    } while(!bd.isSingleton());
                } while(bd.isLazyInit());

                if (this.isFactoryBean(beanName)) {
                    final FactoryBean<?> factory = (FactoryBean)this.getBean("&" + beanName);
                    boolean isEagerInit;
                    if (System.getSecurityManager() != null && factory instanceof SmartFactoryBean) {
                        isEagerInit = ((Boolean)AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
                            public Boolean run() {
                                return ((SmartFactoryBean)factory).isEagerInit();
                            }
                        }, this.getAccessControlContext())).booleanValue();
                    } else {
                        isEagerInit = factory instanceof SmartFactoryBean && ((SmartFactoryBean)factory).isEagerInit();
                    }

                    if (isEagerInit) {
                        this.getBean(beanName);
                    }
                } else {
            //注册bean
this.getBean(beanName); } } } }

是使用getBean方法来通过反射将所有未创建的实例创建出来

  使用嵌入式Servlet容器:

     优点:   简单,便携

     缺点:   默认不支持jsp,优化定制比较复杂

使用外置Servlet容器的步骤:

  1  必须创建war项目,需要剑豪web项目的目录结构

  2  嵌入式Tomcat依赖scope指定provided

  3  编写SpringBootServletInitializer类子类,并重写configure方法


public class ServletInitializer extends SpringBootServletInitializer {  
  
    @Override  
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {  
        return application.sources(SpringBoot04WebJspApplication.class);  
    }  
} 

 

       4  启动服务器

jar包和war包启动区别

    jar包:执行SpringBootApplication的run方法,启动IOC容器,然后创建嵌入式Servlet容器

 war包:  先是启动Servlet服务器,服务器启动Springboot应用(springBootServletInitizer),然后启动IOC容器

Servlet 3.0+规则

    1  服务器启动(web应用启动),会创建当前web应用里面所有jar包里面的ServletContainerlnitializer实例

     2 ServletContainerInitializer的实现放在jar包的META-INF/services文件夹下

   3  还可以使用@HandlesTypes注解,在应用启动的时候加载指定的类。

外部Tomcat流程以及原理

  ①  启动Tomcat

  ②  根据上述描述的Servlet3.0+规则,可以在Spring的web模块里面找到有个文件名为javax.servlet.ServletContainerInitializer的文件,而文件的内容为org.springframework.web.SpringServletContainerInitializer,用于加载SpringServletContainerInitializer类

  ③看看SpringServletContainerInitializer定义


@HandlesTypes(WebApplicationInitializer.class)
public class SpringServletContainerInitializer implements ServletContainerInitializer {

    /**
     * Delegate the {@code ServletContext} to any {@link WebApplicationInitializer}
     * implementations present on the application classpath.
     * <p>Because this class declares @{@code HandlesTypes(WebApplicationInitializer.class)},
     * Servlet 3.0+ containers will automatically scan the classpath for implementations
     * of Spring's {@code WebApplicationInitializer} interface and provide the set of all
     * such types to the {@code webAppInitializerClasses} parameter of this method.
     * <p>If no {@code WebApplicationInitializer} implementations are found on the classpath,
     * this method is effectively a no-op. An INFO-level log message will be issued notifying
     * the user that the {@code ServletContainerInitializer} has indeed been invoked but that
     * no {@code WebApplicationInitializer} implementations were found.
     * <p>Assuming that one or more {@code WebApplicationInitializer} types are detected,
     * they will be instantiated (and <em>sorted</em> if the @{@link
     * org.springframework.core.annotation.Order @Order} annotation is present or
     * the {@link org.springframework.core.Ordered Ordered} interface has been
     * implemented). Then the {@link WebApplicationInitializer#onStartup(ServletContext)}
     * method will be invoked on each instance, delegating the {@code ServletContext} such
     * that each instance may register and configure servlets such as Spring's
     * {@code DispatcherServlet}, listeners such as Spring's {@code ContextLoaderListener},
     * or any other Servlet API componentry such as filters.
     * @param webAppInitializerClasses all implementations of
     * {@link WebApplicationInitializer} found on the application classpath
     * @param servletContext the servlet context to be initialized
     * @see WebApplicationInitializer#onStartup(ServletContext)
     * @see AnnotationAwareOrderComparator
     */
    @Override
    public void onStartup(Set<Class<?>> webAppInitializerClasses, ServletContext servletContext)
            throws ServletException {

        List<WebApplicationInitializer> initializers = new LinkedList<WebApplicationInitializer>();

        if (webAppInitializerClasses != null) {
            for (Class<?> waiClass : webAppInitializerClasses) {
                // Be defensive: Some servlet containers provide us with invalid classes,
                // no matter what @HandlesTypes says...
                if (!waiClass.isInterface() && !Modifier.isAbstract(waiClass.getModifiers()) &&
                        WebApplicationInitializer.class.isAssignableFrom(waiClass)) {
                    try {
                //为所有的WebApplicationInitializer类型创建实例,并加入集合中 initializers.add((WebApplicationInitializer) waiClass.newInstance()); }
catch (Throwable ex) { throw new ServletException("Failed to instantiate WebApplicationInitializer class", ex); } } } } if (initializers.isEmpty()) { servletContext.log("No Spring WebApplicationInitializer types detected on classpath"); return; } servletContext.log(initializers.size() + " Spring WebApplicationInitializers detected on classpath"); AnnotationAwareOrderComparator.sort(initializers);
      //调用每一个WebApplicationInitializer实例的onstartup方法
for (WebApplicationInitializer initializer : initializers) { initializer.onStartup(servletContext); } } }

 在上面一段长长的注释中可以看到,SpringServletContainerInitializer将@HandlesTypes(WebApplicationInitializer.class)标注的所有WebApplicationInitializer这个类型的类都传入到onStartup方法的Set参数中,并通过反射为这些WebApplicationInitializer类型的类创建实例;

  ④  方法最后,每一个WebApplicationInitilizer实现调用自己onstartup方法

  ⑤  而WebApplicationInitializer有个抽象实现类SpringBootServletInitializer(记住我们继承了该抽象类),则会调用每一个WebApplicationInitializer实例(包括SpringBootServletInitializer)的onStartup方法:


public abstract class SpringBootServletInitializer implements WebApplicationInitializer {  
  
    //other code...  
      
    @Override  
    public void onStartup(ServletContext servletContext) throws ServletException {  
        // Logger initialization is deferred in case a ordered  
        // LogServletContextInitializer is being used  
        this.logger = LogFactory.getLog(getClass());  
        //创建IOC容器  
        WebApplicationContext rootAppContext = createRootApplicationContext(  
                servletContext);  
        if (rootAppContext != null) {  
            servletContext.addListener(new ContextLoaderListener(rootAppContext) {  
                @Override  
                public void contextInitialized(ServletContextEvent event) {  
                    // no-op because the application context is already initialized  
                }  
            });  
        }  
        else {  
            this.logger.debug("No ContextLoaderListener registered, as "  
                    + "createRootApplicationContext() did not "  
                    + "return an application context");  
        }  
    }  
  
    protected WebApplicationContext createRootApplicationContext(  
            ServletContext servletContext) {  
        //创建Spring应用构建器,并进行相关属性设置  
        SpringApplicationBuilder builder = createSpringApplicationBuilder();  
        StandardServletEnvironment environment = new StandardServletEnvironment();  
        environment.initPropertySources(servletContext, null);  
        builder.environment(environment);  
        builder.main(getClass());  
        ApplicationContext parent = getExistingRootWebApplicationContext(servletContext);  
        if (parent != null) {  
            this.logger.info("Root context already created (using as parent).");  
            servletContext.setAttribute(  
                    WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, null);  
            builder.initializers(new ParentContextApplicationContextInitializer(parent));  
        }  
        builder.initializers(  
                new ServletContextApplicationContextInitializer(servletContext));  
        builder.contextClass(AnnotationConfigEmbeddedWebApplicationContext.class);  
          
        //调用configure方法,创建war类型的web项目后,由于编写SpringBootServletInitializer的子类重写configure方法,所以此处调用的是我们定义的子类重写的configure方法  
        builder = configure(builder);  
          
        //通过构建器构建了一个Spring应用  
        SpringApplication application = builder.build();  
        if (application.getSources().isEmpty() && AnnotationUtils  
                .findAnnotation(getClass(), Configuration.class) != null) {  
            application.getSources().add(getClass());  
        }  
        Assert.state(!application.getSources().isEmpty(),  
                "No SpringApplication sources have been defined. Either override the "  
                        + "configure method or add an @Configuration annotation");  
        // Ensure error pages are registered  
        if (this.registerErrorPageFilter) {  
            application.getSources().add(ErrorPageFilterConfiguration.class);  
        }  
        //启动Spring应用  
        return run(application);  
    }  
      
    //Spring应用启动,创建并返回IOC容器  
    protected WebApplicationContext run(SpringApplication application) {  
        return (WebApplicationContext) application.run();  
    }  
      
} 

   SpringBootServletInitializer实例执行onStartup方法的时候会通过createRootApplicationContext方法来执行run方法,接下来的过程就同以jar包形式启动的应用的run过程一样了,在内部会创建IOC容器并返回,只是以war包形式的应用在创建IOC容器过程中,不再创建Servlet容器了。

【Spring Boot】配置嵌入式Servlet容器及启动原理 SpringBoot配置嵌入式Servlet容器定制和修改Servlet容器相关配置全局配置文件编写WebServerFactoryCustomizer注册Servlet三大组件注册Servlet注册Filter注册ListenerSpringBoot注册DispatcherServlet切换嵌入式Servlet容器 SpringBoot默认使用Tomcat作为嵌入式的Servlet容器 定制和修改Servlet容器相关配置 可以通过全局配置文件或者自己编写WebServerFactoryCustomiz 阅读详情

相关推荐

解密SpringBoot底层原理源码,从手写框架开始

解密SpringBoot底层原理源码,从手写框架开始

SpringBoot 中的 ServletInitializer

(一)代码部分 ServletInitializer 中代码 在 SpringBootServletInitializer 中 在 WebApplicationInitializer 中 (二)分析 一、对 WebApplicationInitializer 的理解 现在JavaConfig配置方式在逐步取代xml配置方式。而WebApplicationInitia...

殇莫忆的博客 5万+

深入讲解spring boot中servlet的启动过程与原理

主要给大家介绍了关于spring boot中servlet启动过程与原理的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧

SpringBoot是如何创建ServletContext

1处ServletContextInitializer封装进了tomcatStarter中,最后starter被添加到了tomcat的context中,在tomcat启动的时候会调用ServletContextInitializer的startUp方法。此处thisselfInitialize返回的是函数式方法实现,类似匿名内部类,而不是直接调用(注理解了很久,PS断点一直不进去,很奇怪),此处返回一个ServletContextInitialzer的实现。过程太长了,省略了一部分.............

zhao_god的专栏 1234

AI工作流革命:从n8n到Sora2,揭秘自动化视频创作的底层逻辑

本文深入探讨了AI工作流在自动化视频创作中的应用,重点介绍了n8n、Coze和Sora2的组合如何实现从链接输入到视频输出的全流程自动化。通过三层架构解析、关键技术模块优化及成本控制策略,这套方案显著提升了视频生产效率,适用于电商、热点追踪等多种场景。

gg901的博客 1090

ES8311音频Codec避坑指南:从I2C通信、电平匹配到回环测试的保姆级调试笔记

本文详细解析了ES8311音频编解码芯片的调试全流程,涵盖I2C通信建立、电平匹配、主从模式配置等关键环节。通过真实案例和实用技巧,帮助工程师快速定位和解决音频Codec常见问题,提升硬件调试效率。特别针对回环测试、功耗分析等高频故障点提供了可复用的排查方法论。

weixin_42532938的博客 278

SpringBoot——Spring Boot 中使用 Servlet

1 Spring Boot 中使用 Servlet Spring Boot 中使用 Servlet有两种方式 方式一:通过注解扫描方式实现 方式二:通过 SpringBoot 的配置类实现(组件注册) 2 方式一:通过注解扫描方式实现 创建一个servlet类 package com.liuhaiyang.springboot.servlet; import javax.servlet.ServletException; import javax.servlet.annotation..

莫得感情得码农 7183

SVA学习笔记(1)——property基本语法及巧用define与property

巧用define与property,让代码更加灵活

craftsman2018ship的博客 1574

为什么需要继承SpringBootServletInitializer

在说这个之前先来说一下java中jar包和war包的区别: war包:是做好一个web应用后,通常是网站,打成包部署到容器中,包含所有的资源信息,是可以直接运行的web模块。 jar包:通常是开发时要引用通用类,打成包便于存放管理,通常只是包括一些class文件,在声明了Main_class之后是可以用java命令运行的 好,接下来说下为什么需要继承SpringBootServletIni...

山山来驰的博客 3401

【vsomeip3 教程】SOME/IP 协议详解:基于 AUTOSAR AP 的实现指南

SOME/IP协议在AUTOSAR AP中的实现与应用指南 本文详细介绍了SOME/IP协议在AUTOSAR AP环境下的实现要点。作为一种面向服务的车载以太网中间件协议,SOME/IP支持多种通信模式和服务发现机制。文章系统阐述了协议的网络层要求、消息格式、序列化规范、传输层实现以及错误处理机制,重点分析了TCP/UDP传输特性、Service Discovery时间参数和SOME/IP-TP分段传输等核心技术。同时提供了性能优化、配置建议和兼容性考虑等最佳实践,帮助开发者在满足AUTOSAR规范的前提下

探索C++编程的奥秘,分享深入的技术见解和实践,旨在激发读者创造力与解决问题的思维。 590

YOLOV12进阶:MSDA多尺度空洞注意力机制解析与实战,突破检测尺度瓶颈

在目标检测中,“尺度差异”是个老大难问题——大目标占据画面大半,小目标可能只有几个像素,普通模型很难同时精准检测。而MSDA(Multi-Scale Dilated Attention,多尺度空洞注意力)就像给模型配备了“变焦眼镜”,能同时关注不同尺度的目标,让YOLOV12在大、中、小目标检测上都能表现出色。这篇教程会带你从原理到实操,掌握这个强大的注意力机制,让你的检测模型真正“通吃”各种尺度的目标。MSDA的“多尺度空洞注意力”设计,是目标检测突破尺度瓶颈的关键一步。

know_F0727的博客 264

Spring Boot 使用外置的 Servlet 容器&启动原理

嵌入式 Servlet 容器:应用打成可执行的jar包 优点:简单,便携 缺点:默认不支持JSP,优化定制比较复杂(使用定制器【ServerProperties、自定义EmbeddedServletContainerCustomizer】,自己编写嵌入式Servlet容器的创建工厂【EmbeddedServletContainerFactory】 ); 外置的Servle...

Java_Glory的博客 309

自动化测试与AI的结合应用

自动化测试,人工智能,机器学习,深度学习,测试用例生成,缺陷预测,测试优化 1. 背景介绍 在软件开发领域,自动化测试已成为不可或缺的一部分,它可以提高测试效率、降低测试成本,并确保软件质量。然而,传统的自动化测试方法往往依赖于人工编写的测试用例,这不仅耗时费力,而且难以应对复杂软件

AI架构师小马 2248

Spring boot中servlet启动原理

启动过程及原理 1 spring boot 应用启动运行run方法 StopWatch stopWatch = new StopWatch(); stopWatch.start(); ConfigurableApplicationContext context = null; FailureAnalyzers analyzers = null; configureHeadlessProperty(); SpringAppl

z69183787的专栏 821

C++软件异常分析概述

本文将详细讲述Windows系统中软件异常的分类以及常用的排查方法,给大家提供一个借鉴与参考。

dvlinker的技术专栏 4万+

OpenClaw常见4大赋能工作场景

OpenClaw不仅仅是一个AI工具,更像是个人与企业的“数字操作系统”——它连接大模型与真实世界,让“思考”与“行动”无缝闭环。

王国平的博客 629

Spring Boot 嵌入式Servlet容器启动原理

1,Spring Boot 应用启动运行run方法 2,refreshContext(context);Spring Boot刷新IOC容器【创建IOC容器对象,并初始化容器,创建容器中的每一个组件】;如果是web应用创建一个web的ioc容器:AnnotationConfigEmbeddedWebApplicationContext,否则创建一个默认的容器:AnnotationConfigAp...

Java_Glory的博客 328

贝叶斯统计 [韦来生编]

贝叶斯(Bayes)统计是近几十年来迅速发展起来的数理统计的一个重要分支。贝叶斯方法与经典统计方法的主要不同之处是进行统计推断时除了利用样本信息外,还要利用参数的先验信息,因此可以提高统计推断或统计决策的效果。它在经济、金融、生物、医学、自然科学和社会科学等许多领域具有广泛的应用。贝叶斯方法的研究已渗透到了统计学的几乎所有领域。作者在给中国科学技术大学概率论与数理统计专业本科生开设的“数理统计”课程中有一章专门讲授“贝叶斯方法和统计决策理论”,近十年来也给中国科学技术大学概率统计专业研究生开设过几次“贝叶斯分析”课。本书是在对过去讲稿的内容作了适当的增减和调整的基础上完成的。  本书共分六章。第1章是绪论,介绍了贝叶斯统计的若干基本概念,同时对必要的数理统计的基础知识有重点地作了回顾。第二章介绍了确定先验分布的若干可供选择的方法。第三章介绍了几类常见统计模型参数的后验分布的主要结果和计算方法。第四章和第五章分别介绍了“贝叶斯统计推断”和“贝叶斯统计决策”的内容。第六章介绍了贝叶斯统计计算的若干方法,包括蒙特卡洛方法和马尔可夫链蒙特卡洛(MCMC)方法以及相关统计软件的简介。本书的每一章附右大量的例题和习题,书末附有常用的几个表格和部分习题解答供读者查用。  大约可在54学时内讲授本书的第1章至第六章的主要内容,教师可根据学时需要选讲本书第1章至第六章的部分内容。书中标“*”号的章节可略去不讲,留给读者作为阅读材料。第六章例题中的R代码和部分例题的数据文件等可从作者个人主页下载。  作者在编写本书的过程中参考了J.O.Berger教授的《统计决策论及贝叶斯分析》和茆诗松教授编写的《贝叶斯统计》等书中的一些内容,以及《贝叶斯分析》一书中由张伟平博士编写的有关贝叶斯统计计算的一些内容。在此表示衷心感谢。  本书编写准备过程中,中国科学技术大学统计与金融系的几个研究生帮助完成了本书部分中文的录入和排版,作者对他们的辛勤工作表示真诚的感谢。高等教育出版社为本书的出版给予了大力支持。在此一并致谢。

servlet容器_Spring Boot学习04_外部Servlet容器启动原理

1、创建使用外部Servlet容器的Spring Boot的项目,会多一个类。2、通过外部的tomcat的启动时会发现先启动tomcat,然后就会启动之前Spring Boot的主配置类程序。3、在Servlet3.0的有几个规范​ 1)、服务器启动(web应用启动)会创建当前web应用里面每一个jar包里面ServletContainerInitializer实例​ 2)、ServletCont...

weixin_39784774的博客 88

IMSL CNL 7.0.0 (x86-64)Crack

IMSL CNL 7.0.0 (x86-64)Crack intel的算法库破解文件,这是C++版本的破解文件

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

spring boot 外部Servlet容器启动原理

1.启动Tomcat 2.org\springframework\spring-web\4.3.14.RELEASE\spring-web-4.3.14.RELEASE.jar!\META-INF\services\javax.servlet.ServletContainerInitializer: Spring的web模块里面有这个文件:**org.springframework.web.SpringServletContainerInitializer** 3.SpringServletC

CB_Beginner的博客 314

pscad IEEE标准系统搭建说明

pscad IEEE标准系统搭建说明,包含典型的IEEE 9节点、14节点、30节点、39节点和118节点系统。内含标准测试系统的原始数据和潮流结果。

java war 原理_深入讲解spring boot中servlet的启动过程与原理

前言本文主要介绍了关于spring boot中servlet启动过程与原理的相关内容,下面话不多说了,来一起看看详细的介绍吧启动过程与原理:1 spring boot 应用启动运行run方法StopWatch stopWatch = new StopWatch();stopWatch.start();ConfigurableApplicationContext context = null;Fai...

weixin_29825861的博客 306

Spring boot中嵌入式Servlet容器的配置和启动原理

以下分析基于Springboot2.0以上版本,1.X版本跟2.0以上版本源码差异性较大 嵌入式Servlet容器的自动配置原理流程如下: SpringBoot 根据的依赖信息(默认是tomcat),创建对应的WebServerFactoryCustomizer(定制器,用来定制一些属性,默认为tomcat 所以就是定制tomcat的一些属性); WebServerFactoryCustomizerBeanPostProcessor(web工厂定制器的后置处理器)获取所有类型为web服务工厂定制器的组件(

湟同学你好的博客 567

spring boot 嵌入式Servlet容器启动原理

1.)SpringBoot应用启动运行run方法 2.、refreshContext(context);SpringBoot刷新IOC容器【创建IOC容器对象,并初始化容器,创建容器中的每一个组件】;如果是web应用创建**AnnotationConfigEmbeddedWebApplicationContext**,否则:**AnnotationConfigApplicationContext** 3)、refresh(context);**刷新刚才...

CB_Beginner的博客 156
上一篇: Eureka error "java.net.UnknownHostException:
下一篇: n级阶梯,每次走一步或两步,问最多有多少种走法 二叉树实现(面试题)
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值