深入解析SpringBoot启动原理

2023-11-14

1.启动类中的SpringApplication.run方法会创建一个SpringApplication的实例,并做一些初始化工作
@SpringBootApplication
@Slf4j
public class HuotuUserServiceApplication {
    public static void main(String[] args) {
        ApplicationContext context = SpringApplication.run(HuotuUserServiceApplication.class, args);
        String[] profiles = context.getEnvironment().getActiveProfiles();

        for (String profile : profiles) {
            log.info("用户服务当前环境 : {}", profile);
        }
    }
}

public static ConfigurableApplicationContext run(Class<?>[] primarySources,
            String[] args) {
    //先实例化ApringApplication,然后调用其run方法。接下来我们一个个分析。
    return new SpringApplication(primarySources).run(args);
}

public SpringApplication(ResourceLoader resourceLoader, Class<?>... primarySources) {
    this.resourceLoader = resourceLoader;
    Assert.notNull(primarySources, "PrimarySources must not be null");
    this.primarySources = new LinkedHashSet<>(Arrays.asList(primarySources));
    //推断当前应用是否是web环境,推断的标准是ClassLoader能否加载到 javax.servlet.Servlet和org.springframework.web.context.ConfigurableWebApplicationContext这两个类,能同时加载到说明是web环境
    this.webApplicationType = WebApplicationType.deduceFromClasspath();
    
    //下面两句是给SpringApplication实例添加初始化器以及监听器,spring.factories文件(classpath下)里面的初始化器和监听器都会注册进来
    setInitializers((Collection) getSpringFactoriesInstances(
            ApplicationContextInitializer.class));
    setListeners((Collection) getSpringFactoriesInstances(ApplicationListener.class));
    
    this.mainApplicationClass = deduceMainApplicationClass();
}

2.SpringApplication初始化完成,执行其run方法启动容器
public ConfigurableApplicationContext run(String... args) {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    ConfigurableApplicationContext context = null;
    Collection<SpringBootExceptionReporter> exceptionReporters = new ArrayList<>();
    configureHeadlessProperty();
    SpringApplicationRunListeners listeners = getRunListeners(args);
    listeners.starting();
    try {
        ApplicationArguments applicationArguments = new DefaultApplicationArguments(
                args);
        //特别注意这一步,环境准备好之后,会发布一个ApplicationEnvironmentPreparedEvent事件,然后创建一个root ApplicationContext
        ConfigurableEnvironment environment = prepareEnvironment(listeners,
                applicationArguments);
        configureIgnoreBeanInfo(environment);
        Banner printedBanner = printBanner(environment);
        context = createApplicationContext();
        exceptionReporters = getSpringFactoriesInstances(
                SpringBootExceptionReporter.class,
                new Class[] { ConfigurableApplicationContext.class }, context);
        prepareContext(context, environment, listeners, applicationArguments,
                printedBanner);
        refreshContext(context);
        afterRefresh(context, applicationArguments);
        stopWatch.stop();
        if (this.logStartupInfo) {
            new StartupInfoLogger(this.mainApplicationClass)
                    .logStarted(getApplicationLog(), stopWatch);
        }
        listeners.started(context);
        callRunners(context, applicationArguments);
    }
    catch (Throwable ex) {
        handleRunFailure(context, ex, exceptionReporters, listeners);
        throw new IllegalStateException(ex);
    }

    try {
        listeners.running(context);
    }
    catch (Throwable ex) {
        handleRunFailure(context, ex, exceptionReporters, null);
        throw new IllegalStateException(ex);
    }
    return context;
}

//准备环境
private ConfigurableEnvironment prepareEnvironment(
            SpringApplicationRunListeners listeners,
            ApplicationArguments applicationArguments) {
    // Create and configure the environment
    ConfigurableEnvironment environment = getOrCreateEnvironment();
    configureEnvironment(environment, applicationArguments.getSourceArgs());
    //环境准备好之后,会发布一个ApplicationEnvironmentPreparedEvent事件
    listeners.environmentPrepared(environment);
    bindToSpringApplication(environment);
    if (!this.isCustomEnvironment) {
        environment = new EnvironmentConverter(getClassLoader())
                .convertEnvironmentIfNecessary(environment, deduceEnvironmentClass());
    }
    ConfigurationPropertySources.attach(environment);
    return environment;
}

//ApplicationEnvironmentPreparedEvent事件会被BootstrapApplicationListener监听到
@Override
public void environmentPrepared(ConfigurableEnvironment environment) {
    this.initialMulticaster.multicastEvent(new ApplicationEnvironmentPreparedEvent(
            this.application, this.args, environment));
}

BootstrapApplicationListener的onApplicationEvent方法将会创建另一个SpringApplication的实例,构建一个StandardEnvironment环境,以及产生一个root ApplicationContext(这个容器实际上是一个AnnotationConfigApplicationContext,
它产生的时间远远早于第一个SpringApplication的实例产生的容器,从启动日志也可以看出来)

private ConfigurableApplicationContext bootstrapServiceContext(
            ConfigurableEnvironment environment, final SpringApplication application,
            String configName) {
    StandardEnvironment bootstrapEnvironment = new StandardEnvironment();
    MutablePropertySources bootstrapProperties = bootstrapEnvironment
            .getPropertySources();
    for (PropertySource<?> source : bootstrapProperties) {
        bootstrapProperties.remove(source.getName());
    }
    String configLocation = environment
            .resolvePlaceholders("${spring.cloud.bootstrap.location:}");
    Map<String, Object> bootstrapMap = new HashMap<>();
    bootstrapMap.put("spring.config.name", configName);
    // if an app (or test) uses spring.main.web-application-type=reactive, bootstrap will fail
    // force the environment to use none, because if though it is set below in the builder
    // the environment overrides it
    bootstrapMap.put("spring.main.web-application-type", "none");
    if (StringUtils.hasText(configLocation)) {
        bootstrapMap.put("spring.config.location", configLocation);
    }
    bootstrapProperties.addFirst(
            new MapPropertySource(BOOTSTRAP_PROPERTY_SOURCE_NAME, bootstrapMap));
    for (PropertySource<?> source : environment.getPropertySources()) {
        if (source instanceof StubPropertySource) {
            continue;
        }
        bootstrapProperties.addLast(source);
    }
    // TODO: is it possible or sensible to share a ResourceLoader?
    //这里会创建另一个(非Web环境)SpringApplication
    SpringApplicationBuilder builder = new SpringApplicationBuilder()
            .profiles(environment.getActiveProfiles()).bannerMode(Mode.OFF)
            .environment(bootstrapEnvironment)
            // Don't use the default properties in this builder
            .registerShutdownHook(false).logStartupInfo(false)
            .web(WebApplicationType.NONE);
    final SpringApplication builderApplication = builder.application();
    if(builderApplication.getMainApplicationClass() == null){
        // gh_425:
        // SpringApplication cannot deduce the MainApplicationClass here
        // if it is booted from SpringBootServletInitializer due to the
        // absense of the "main" method in stackTraces.
        // But luckily this method's second parameter "application" here
        // carries the real MainApplicationClass which has been explicitly
        // set by SpringBootServletInitializer itself already.
        builder.main(application.getMainApplicationClass());
    }
    if (environment.getPropertySources().contains("refreshArgs")) {
        // If we are doing a context refresh, really we only want to refresh the
        // Environment, and there are some toxic listeners (like the
        // LoggingApplicationListener) that affect global static state, so we need a
        // way to switch those off.
        builderApplication
                .setListeners(filterListeners(builderApplication.getListeners()));
    }
    builder.sources(BootstrapImportSelectorConfiguration.class);
    final ConfigurableApplicationContext context = builder.run();
    // gh-214 using spring.application.name=bootstrap to set the context id via
    // `ContextIdApplicationContextInitializer` prevents apps from getting the actual
    // spring.application.name
    // during the bootstrap phase.
    context.setId("bootstrap");
    // Make the bootstrap context a parent of the app context
    addAncestorInitializer(application, context);
    // It only has properties in it now that we don't want in the parent so remove
    // it (and it will be added back later)
    bootstrapProperties.remove(BOOTSTRAP_PROPERTY_SOURCE_NAME);
    mergeDefaultProperties(environment.getPropertySources(), bootstrapProperties);
    return context;
}

Root ApplicationContext启动之后,回过头来会创建第一个SpringApplication对应的容器,这是一个AnnotationConfigServletWebServerApplicationContext容器,它是一个web容器,
AnnotationConfigServletWebServerApplicationContext被创建后,它的parent容器会被设置为AnnotationConfigApplicationContext容器(也就是系统中产生的第一个容器 root ApplicationContext)

原理是这样的:
//org.springframework.boot.SpringApplication类中
private void prepareContext(ConfigurableApplicationContext context,
            ConfigurableEnvironment environment, SpringApplicationRunListeners listeners,
            ApplicationArguments applicationArguments, Banner printedBanner) {
    context.setEnvironment(environment);
    postProcessApplicationContext(context);
    //初始化这个容器,这一步很关键
    applyInitializers(context);
    listeners.contextPrepared(context);
    if (this.logStartupInfo) {
        logStartupInfo(context.getParent() == null);
        logStartupProfileInfo(context);
    }
    // Add boot specific singleton beans
    ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
    beanFactory.registerSingleton("springApplicationArguments", applicationArguments);
    if (printedBanner != null) {
        beanFactory.registerSingleton("springBootBanner", printedBanner);
    }
    if (beanFactory instanceof DefaultListableBeanFactory) {
        ((DefaultListableBeanFactory) beanFactory)
                .setAllowBeanDefinitionOverriding(this.allowBeanDefinitionOverriding);
    }
    // Load the sources
    Set<Object> sources = getAllSources();
    Assert.notEmpty(sources, "Sources must not be empty");
    load(context, sources.toArray(new Object[0]));
    listeners.contextLoaded(context);
}

//org.springframework.boot.SpringApplication类中
@SuppressWarnings({ "rawtypes", "unchecked" })
protected void applyInitializers(ConfigurableApplicationContext context) {
    for (ApplicationContextInitializer initializer : getInitializers()) {
        Class<?> requiredType = GenericTypeResolver.resolveTypeArgument(
                initializer.getClass(), ApplicationContextInitializer.class);
        Assert.isInstanceOf(requiredType, context, "Unable to call initializer.");
     
      //其中的一个初始化器是BootstrapApplicationListener,它会触发BootstrapApplicationListener.AncestorInitializer.initialize方法
      initializer.initialize(context);
    }
}

//BootstrapApplicationListener.AncestorInitializer类中
@Override
public void initialize(ConfigurableApplicationContext context) {
    while (context.getParent() != null && context.getParent() != context) {
        context = (ConfigurableApplicationContext) context.getParent();
    }
    reorderSources(context.getEnvironment());


   //这个方法最终为当前的AnnotationConfigServletWebServerApplicationContext容器设置parent容器
    new ParentContextApplicationContextInitializer(this.parent)
            .initialize(context);
}

//ParentContextApplicationContextInitializer类
@Override
public void initialize(ConfigurableApplicationContext applicationContext) {
    if (applicationContext != this.parent) {
        //this.parent指向的就是第一个容器对象AnnotationConfigApplicationContext
        applicationContext.setParent(this.parent);
        applicationContext.addApplicationListener(EventPublisher.INSTANCE);
    }
}

容器启动之后,会调用callRunners执行一些命令行参数,注意这里的context是AnnotationConfigServletWebServerApplicationContext容器
private void callRunners(ApplicationContext context, ApplicationArguments args) {
    List<Object> runners = new ArrayList<>();
    runners.addAll(context.getBeansOfType(ApplicationRunner.class).values());
    runners.addAll(context.getBeansOfType(CommandLineRunner.class).values());
    AnnotationAwareOrderComparator.sort(runners);
    for (Object runner : new LinkedHashSet<>(runners)) {
        if (runner instanceof ApplicationRunner) {
            callRunner((ApplicationRunner) runner, args);
        }
        if (runner instanceof CommandLineRunner) {
            callRunner((CommandLineRunner) runner, args);
        }
    }
}

private void callRunner(ApplicationRunner runner, ApplicationArguments args) {
    try {
        (runner).run(args);
    }
    catch (Exception ex) {
        throw new IllegalStateException("Failed to execute ApplicationRunner", ex);
    }
}

private void callRunner(CommandLineRunner runner, ApplicationArguments args) {
    try {
        (runner).run(args.getSourceArgs());
    }
    catch (Exception ex) {
        throw new IllegalStateException("Failed to execute CommandLineRunner", ex);
    }
}

3.启动Web容器
org.springframework.boot.SpringApplication类中
private void refreshContext(ConfigurableApplicationContext context) {
    refresh(context);
    if (this.registerShutdownHook) {
        try {
            context.registerShutdownHook();
        }
        catch (AccessControlException ex) {
            // Not allowed in some environments.
        }
    }
}
protected void refresh(ApplicationContext applicationContext) {
    Assert.isInstanceOf(AbstractApplicationContext.class, applicationContext);
    ((AbstractApplicationContext) applicationContext).refresh();
}

org.springframework.context.support.AbstractApplicationContext类中
public void refresh() throws BeansException, IllegalStateException {
        synchronized (this.startupShutdownMonitor) {
        // Prepare this context for refreshing.
        prepareRefresh();

        // Tell the subclass to refresh the internal bean factory.
        ConfigurableListableBeanFactory beanFactory = obtainFreshBeanFactory();

        // Prepare the bean factory for use in this context.
        prepareBeanFactory(beanFactory);

        try {
            // Allows post-processing of the bean factory in context subclasses.
            postProcessBeanFactory(beanFactory);

            // Invoke factory processors registered as beans in the context.
            invokeBeanFactoryPostProcessors(beanFactory);

            // Register bean processors that intercept bean creation.
            registerBeanPostProcessors(beanFactory);

            // Initialize message source for this context.
            initMessageSource();

            // Initialize event multicaster for this context.
            initApplicationEventMulticaster();

            // Initialize other special beans in specific context subclasses.
            //在这里它是一个模板方法,通过前面的分析,这里是由对应的org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext类实现的
            onRefresh();

            // Check for listener beans and register them.
            registerListeners();

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

            // Last step: publish corresponding event.
            finishRefresh();
        }

        catch (BeansException ex) {
            if (logger.isWarnEnabled()) {
                logger.warn("Exception encountered during context initialization - " +
                        "cancelling refresh attempt: " + ex);
            }

            // Destroy already created singletons to avoid dangling resources.
            destroyBeans();

            // Reset 'active' flag.
            cancelRefresh(ex);

            // Propagate exception to caller.
            throw ex;
        }

        finally {
            // Reset common introspection caches in Spring's core, since we
            // might not ever need metadata for singleton beans anymore...
            resetCommonCaches();
        }
    }
}

org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext类中
@Override
protected void onRefresh() {
    super.onRefresh();
    try {
        //创建WebServer
        createWebServer();
    }
    catch (Throwable ex) {
        throw new ApplicationContextException("Unable to start web server", ex);
    }
}
private void createWebServer() {
    WebServer webServer = this.webServer;
    ServletContext servletContext = getServletContext();
    if (webServer == null && servletContext == null) {
        ServletWebServerFactory factory = getWebServerFactory();
        //这里真正启动tomcat
        this.webServer = factory.getWebServer(getSelfInitializer());
    }
    else if (servletContext != null) {
        try {
            getSelfInitializer().onStartup(servletContext);
        }
        catch (ServletException ex) {
            throw new ApplicationContextException("Cannot initialize servlet context",
                    ex);
        }
    }
    initPropertySources();
}

 

4.为什么默认采用的是Tomcat作为Web服务器

具体原因要归于自动配置类:org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryAutoConfiguration

@Bean
//当类路径下存在org.apache.catalina.startup.Tomcat,创建TomcatServletWebServerFactoryCustomizer 
@ConditionalOnClass(name = "org.apache.catalina.startup.Tomcat")
public TomcatServletWebServerFactoryCustomizer tomcatServletWebServerFactoryCustomizer(
      ServerProperties serverProperties) {
   return new TomcatServletWebServerFactoryCustomizer(serverProperties);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

深入解析SpringBoot启动原理 的相关文章

  • 基于STM32的FreeRTOS学习之中断测试实验(五)

    记录一下 方便以后翻阅 本章内容是接着上一章节进行的实际演练 1 实验目的 FreeRTOS可以屏蔽优先级低于configMAX SYSCALL INTERRUPT PRIORITY的中断 不会屏蔽高于其的中断 本次实验就是验证这个说法 本
  • nui-app vue.js项目实战---微信小程序

    基于uni app的小程序项目编写 什么是uni app uni app基于vue js开发的前端应用框架 同一套代码可以在ios 安卓 h5 以及各种小程序使用 开发工具 HBuilderX 下载开发版地址 主要是因为其模板丰富 操作简单
  • Cookie + Session 登入

    Cookie Session 登入 在讲Cookie Session 登入前 我们应该先来了解一下 为什么会有这两个东西 因为HTTP 是一种無狀態 stateless 的协议 所以每次请求都是獨立的 伺服器端无法判断本次请求和上一次请求是
  • java 远程shell脚本_java通过ssh连接服务器执行shell命令详解及实例

    java通过ssh连接服务器执行shell命令详解 java通过ssh连接服务器执行shell命令 JSch 是SSH2的一个纯Java实现 它允许你连接到一个sshd 服务器 使用端口转发 X11转发 文件传输等等 你可以将它的功能集成到
  • 抖音告白代码java,(新版失效)去抖音水印简单分析教程(附带java版代码)

    Python 纯文本查看 复制代码 20200908095807 https www iesdouyin com web api v2 aweme iteminfo item ids 6558232015454342407 ab type
  • 记录下今晚软件测试遇到的大题

    方法如下 测试用例设计方法之边界值分析方法 51Testing软件测试网 软件测试用例分析 习题完美整合版 搜档网 下面是选择排序的程序 其中datalist是数据表 它有两个数据成员 一是元素类型为Element的数组V 另一个是数组大小
  • 安装VS2019 提示 Visual C++ 2015-2019 x64 redistributable安装失败

    最近安装VS2019和UE4的时候总是弹出提示框 忘记截图了 找了张类似的 点击OK之后会弹出下面的对话框 度娘给出茫茫多的解决方案 大部分都是说缺少vc 2015或者vc 2017的相应库 需要先安装低版本库 试了大半天都不能解决 吐血
  • React Native-自定义组件之Slider

    一 背景 最近在进行原生模块改造RN的时候需要用到一个定制的可拖动进度条 但发现react native自带的Slider仅仅是在iOS平台上支持 所以决定自己来定制一个 二 设计思路 组合基础组件和View和Image 搭配PanResp
  • v-model数据绑定到对象的小技巧

    在前面写了v model obj a 后 下面的对象内不用写a这个属性 直接用空对象abj js这类弱语言 会自动将a这个属性set到obj的对象中去 例如 前面绑定了对象中的属性 在后面写对象的时候 可以不写对象属性 直接写一个空对象 在
  • 脑电特征中的微分熵(DE)计算

    最近参加了一个脑电相关的竞赛 其中有一个赛道是情绪识别 根据脑电数据将情绪进行4分类 查了一些文献 使用了包括时域 频域 空间域的一些特征 最后发现微分熵作为特征的分类效果最好 相关参考文献整理下载 https download csdn
  • vcruntime140.dll丢失的解决方法,vcruntime140.dll下载安装教程

    文件vcruntime140 dll需要在电脑打开一个浏览器才能下载顶部输入 dll修复程序 site 按下键盘的回车键打开 然后点击进入下载dll文件安装包 dll文件安装包下载需要点击解压 然后把解压好的文件点击打开 开始安装丢失的vc
  • android 复制文件速度,memcpy速度太慢?掌握这个技术让内存拷贝效率成倍提升

    memcpy是C C 的一个标准函数 原型void memcpy void dest const void src size t n 用于从源src所指的内存地址的起始位置开始拷贝n个字节到目标dest所指的内存地址的起始位置中 neon是
  • 华为OD机试真题B卷 Java 实现【字符串分隔】,附详细解题思路

    目录 专栏导读 一 题目描述 二 输入描述 三 输出描述 四 解题思路 五 Java算法源码 六 效果展示 华为OD机试 2023B卷题库疯狂收录中 刷题点这里 专栏导读 本专栏收录于 华为OD机试 JAVA 真题 A卷 B卷 刷的越多 抽
  • 如何使用Blender建3D汉字(保姆级别的详细)

    未来的游戏开发程序媛 现在的努力学习菜鸡 本专栏是我关于建模的学习笔记 本篇是如何使用Blender建3D汉字 这是这个专栏的第一篇 因为不知道把这篇放到哪里 就开了个新的 如何使用Blender建3D汉字 就这种的 如果是的话可以接着往下
  • 计算机科学和PYTHON编程导论_15_概率与分布

    随机程序 掷骰子 import random def rollDie 返回一个1 6的随机整数 return random choice 1 2 3 4 5 6 def rollN n result for i in range n res
  • Matlab回归分析

    线性回归 在实际中 对于情况较复杂的实际问题 因素不易化简 作用机理不详 可直接使用数据组建模 寻找简单的因果变量之间的数量关系 从而对未知的情形作预报 这样组建的模型为拟合模型 拟合模型的组建主要是处理好观测数据的误差 使用数学表达式从数
  • 用gdb.attach()在gdb下断点但没停下的情况及解决办法

    在python中 如果导入了pwntools 就可以使用里面的gdb attach io 的命令来下断点 但是这一次鼠鼠遇到了一个情况就是下了断点 但是仍然无法在断点处开始运行 奇奇怪怪 这是我的攻击脚本 我们运行一下 可以看到其实已经运行
  • Python入门--with语句

    with语句 上下文管理器 with语句可以自动管理上下文资源 不论什么原因跳出with块 都能确保文件的正确关闭 以此来达到释放资源的目的 with open 上下文管理器 with open a txt r as file as起个别名
  • Unity3d-游戏中的小地图制作

    方法一 利用NGJ MiniMap插件 1 导入该插件后 在Mesh Version gt Prefabs中 将NJG MiniMap 2D 拖入到场景中 2 在Hierarchy中点击MiniMap 位于NJG MiniMap 2D gt

随机推荐

  • inc si指令的作用_到底什么是链接,它起到了什么作用?

    几十年以前 计算机刚刚诞生 人们编写程序时 将所有的代码都写在同一个源文件中 经过长期的积累 程序包含了数百万行的代码 以至于人们无法维护这个程序了 于是人们开始寻找新的方法 迫切地希望将程序源代码分散到多个文件中 一个文件一个模块 以便更
  • 如何 debug (调试) maven 插件?

    用惯了 IntelliJ IDEA debug 功能 你知道如何在 IntelliJ IDEA 上调试 maven 插件吗 哈哈哈 那就是这篇文章准没错了 1 准备源码 准备你想要进行 debug 的 maven 插件的源代码 我这里以 m
  • ARM常用汇编指令

    目录 一 汇编基本语法 1 汇编指令的最典型书写模式 二 常用汇编指令 1 push压栈指令 2 pop出栈指令 3 sub指令 4 add指令 5 movs数据传输指令 6 str指令 7 ldr指令 8 bl指令 9 MOVW指令 10
  • C++不定参数,模板函数,模板类详解附实例

    前言 在 C 中 有时我们在写一个函数时并不知道参数的数量和类型 这时需要用到不定参数 模板函数 正文 不定参数 不定参数怎么表示 对于不定参数的表示 就是三个点 注意是英文的点 那么我们在正常使用时函数参数写成这样 funtionType
  • Python 容器序列切片

    视频版教程 Python3零基础7天入门实战视频教程 序列是指内容连续且有序的一类数据容器 前面学的列表 元组 字符串都是序列 并且支持下标索引 切片是指从一个序列中 取出一个子序列 语法 序列 起始下标 结束下标 步长 返回一个新的序列
  • 短文阅读3:Variational Autoencoders (VAEs)

    深度生成网络 VAEs introduction 降维方法 PCA and Autoencoders 降维架构 PCA 问题1 什么是自动编码器autoencoder PCA和Autoencoders之间的关系 Variational Au
  • 【建议收藏】数据库 SQL 入门——数据查询操作(内附演示)

    引言 在上一节中 我们讨论了DML的使用方法 本节我们继续开始DQL的学习 首先回归一下DQL的基于定义 DQL Data Query Language 数据查询语言 用来查询数据库中表的记录 在本节中我们主要讨论DQL的用法以及基本语法
  • 计算机视觉之人脸识别(Yale数据集)--HOG和ResNet两种方法实现

    1 问题描述 在给定Yale数据集上完成以下工作 在给定的人脸库中 通过算法完成人脸识别 算法需要做到能判断出测试的人脸是否属于给定的数据集 如果属于 需要判断出测试的人脸属于数据集中的哪一位 否则 需要声明测试的人脸不属于数据集 这是一个
  • 思维导图 函数

  • PCL点云处理之最小二乘空间直线拟合(3D) (二百零二)

    PCL点云处理之最小二乘空间直线拟合 3D 二百零二 一 算法简介 二 实现代码 三 效果展示 一 算法简介 对于空间中的这样一组点 大致呈直线分布 散乱分布在直线左右 我们可采用最小二乘方法拟合直线 更进一步地 可以通过点到直线的投影 最
  • 5款程序员必备的免费在线画图工具,超级好用!

    点击上方 芋道源码 选择 设为星标 管她前浪 还是后浪 能浪的浪 才是好浪 每天 10 33 更新文章 每天掉亿点点头发 源码精品专栏 原创 Java 2021 超神之路 很肝 中文详细注释的开源项目 RPC 框架 Dubbo 源码解析 网
  • java中的集合基础

    集合介绍 集合类的特点 提供一种存储空间可变的存储模型 存储的数据容量可以发生改变 集合和数组的区别 共同点 都是存储数据的容器 不同点 数组的容量是固定的 集合的容量是可变的 数组可以存基本数据类型和引用数据类型 集合只能存引用数据类型
  • 【Android进阶篇】WebView显示网页详解

    概述 WebView是Android用于显示网页的控件 通过WebView 我们可以查看本地的网页 也可以查看网络资源 本文内容如下 一 加载本地网页 二 加载网络资源 三 在WebView中使用JavaScript和CSS 四 WebCh
  • 多线程案例(1) - 单例模式

    目录 单例模式 饿汉模式 懒汉模式 前言 多线程中有许多非常经典的设计模式 这就类似于围棋的棋谱 这是用来解决我们在开发中遇到很多 经典场景 简单来说 设计模式就是一份模板 可以套用 单例模式 顾名思义 就是一个程序只能含有一个实例 有的场
  • Permission denied

    Permission denied 出现的原因的是 没有权限进行读 写 创建文件 删除文件等操作 解决方法 输入命令 sudo chmod R 777 工作目录 例如 sudo chmode R 777 home HDD 此时就可以在该路径
  • poium测试库介绍

    poium测试库前身为selenium page objects测试库 我在以前的文章中也有介绍过 这可能是最简单的Page Object库 项目的核心是基于Page Objects实现元素定位的封装 该项目由我个人在维护 目前在公司项目中
  • 使用ChatGPT的方式与在其他地方使用它的方式基本相同。以下是一些步骤:

    在中国使用ChatGPT的方式与在其他地方使用它的方式基本相同 以下是一些步骤 访问OpenAI的官方网站 OpenAI 在网站上找到GPT 3或ChatGPT的相关信息 OpenAI提供了详细的API文档 可以帮助你理解如何使用它们 你需
  • mysql数据库之跨表复制

    背景说明 目标库 target db 目标数据表 target tb 将目标库的制定表复制到当前数据库中 包括一下几个方面 一 表结构复制 仅仅复制了表的结构 没有数据 create table current db new tb like
  • Logitech G系鼠标脚本编程,实现鼠标自动定位控制

    利用罗技官方提供的API来写一个鼠标自动定位移动脚本 点击脚本编辑器中的帮助选项 查看罗技官方提供的API说明 有很多实现好的鼠标功能 G series Lua API V8 45 Overview and Reference 下面是我写的
  • 深入解析SpringBoot启动原理

    1 启动类中的SpringApplication run方法会创建一个SpringApplication的实例 并做一些初始化工作 SpringBootApplication Slf4j public class HuotuUserServ