SpringBoot源码解读与原理分析(八)ApplicationContext

文章目录

      • 3.1.2 ApplicationContext
        • 3.1.2.1 ApplicationContext根接口
        • 3.1.2.2 ConfigurableApplicationContext
        • 3.1.2.3 EnvironmentCapable
        • 3.1.2.4 MessageSource
        • 3.1.2.5 ApplicationEventPublisher
        • 3.1.2.6 ResourcePatternResolver
        • 3.1.2.7 AbstractApplicationContext
        • 3.1.2.8 GenericApplicationContext
        • 3.1.2.9 AnnotationConfigApplicationContext
        • 3.1.2.10 AbstractRefreshableConfigApplicationContext
      • 3.1.3 选择ApplicationContext而不是BeanFactory
      • 3.1.4 总结

上一篇详细梳理了BeanFactory的相关特性,本篇梳理BeanFactory的一个扩展——ApplicationContext的相关特性。

3.1.2 ApplicationContext

ApplicationContext是基于BeanFactory的扩展,提供了更强大的特性。

public interface ApplicationContext extends EnvironmentCapable, ListableBeanFactory, HierarchicalBeanFactory,
		MessageSource, ApplicationEventPublisher, ResourcePatternResolver {}

由源码可知,ApplicationContext除了继承BeanFactory接口,还额外继承了几个功能性接口,这些接口共同组成了ApplicationContext扩展的几个核心特性。

3.1.2.1 ApplicationContext根接口

ApplicationContext

Central interface to provide configuration for an application. This is read-only while the application is running, but may be reloaded if the implementation supports this.

第一段:ApplicationContext是为应用程序提供配置的核心接口。在应用程序运行时,它是只读的,但是如果支持的话,它可以重新加载

An ApplicationContext provides:

  • Bean factory methods for accessing application components. Inherited from org.springframework.beans.factory.ListableBeanFactory.
  • The ability to load file resources in a generic fashion. Inherited from the org.springframework.core.io.ResourceLoaderinterface.
  • The ability to publish events to registered listeners. Inherited from the ApplicationEventPublisherinterface.
  • The ability to resolve messages, supporting internationalization. Inherited from the MessageSourceinterface.
  • Inheritance from a parent context. Definitions in a descendant context will always take priority. This means, for example, that a single parent context can be used by an entire web application, while each servlet has its own child context that is independent of that of any other servlet.

第二段:ApplicationContext的特性

  • 访问应用程序组件的BeanFactory方法:继承ListableBeanFactory。
  • 以一般的方式加载文件资源的能力:继承ResourceLoader接口。
  • 发布事件到已注册的监听器的能力:继承ApplicationEventPublisher接口。
  • 解析消息,支持国际化的能力:继承MessageSource接口。
  • 继承父级上下文。后代上下文中的定义优先级更高。这意味着,一个单一的父级上下文可以被整个Wen应用程序使用,而每个Servlet都有自己的子级上下文独立于其他任何Servlet。

In addition to standard org.springframework.beans.factory.BeanFactorylifecycle capabilities, ApplicationContext implementations detect and invoke ApplicationContextAwarebeans as well as ResourceLoaderAware, ApplicationEventPublisherAwareand MessageSourceAwarebeans.

第三段:除了具有标准的BeanFactory生命周期功能,ApplicationContext实现类还检测并调用ApplicationContextAware、ResourceLoaderAware、ApplicationEventPublisherAware、MessageSourceAware接口的Bean。

3.1.2.2 ConfigurableApplicationContext

ConfigurableApplicationContext是ApplicationContext的子接口。

SPI interface to be implemented by most if not all application contexts. Provides facilities to configure an application context in addition to the application context client methods in the org.springframework.context.ApplicationContextinterface.

第一段:ConfigurableApplicationContext会被绝大多数ApplicationContext实现类实现。除了ApplicationContext接口中的应用程序上下文客户端方法,还提供了配置应用程序上下文的功能。

Configuration and lifecycle methods are encapsulated here to avoid making them obvious to ApplicationContext client code. The present methods should only be used by startup and shutdown code.

第二段:配置和生命周期方法都封装在ConfigurableApplicationContext中,目的是避免暴露给ApplicationContext的调用者。当前的方法仅应该由启动和关闭代码使用。

总结:ConfigurableApplicationContext为ApplicationContext提供了“可写”的功能,实现了该接口的实现类可以由客户端代码修改其内部的某些配置。在源码中,可以看到ConfigurableApplicationContext的一些方法:

  • setParent
  • setEnvironment
  • addBeanFactoryPostProcessor
  • addApplicationListener

ConfigurableApplicationContext扩展了一些方法,但一般不希望开发者使用,而只允许刷新容器(refresh)和关闭容器(close)的方法。但如果要定制化ApplicationContext或者对其进行扩展,ConfigurableApplicationContext的扩展则成为重要的切入点。

3.1.2.3 EnvironmentCapable

ApplicationContext继承了EnvironmentCapable。

拓展:在SpringFramework的底层源码中,如果一个接口的名称以Capable结尾,通常意味着可以通过这个接口的某个特定的方法(通常是getXXX())获取特定的组件。

Interface indicating a component that contains and exposes an Environmentreference.

第一段:EnvironmentCapable接口是一个包含并暴露Environment引用的组件。

All Spring application contexts are EnvironmentCapable, and the interface is used primarily for performing instanceofchecks in framework methods that accept BeanFactory instances that may or may not actually be ApplicationContext instances in order to interact with the environment if indeed it is available.

第二段:所有应用程序上下文都适用EnvironmentCapable,该接口主要用于在框架方法中进行instanceof检查,这些方法所接受的BeanFactory实例可能是也可能不是ApplicationContext实例,以便在环境确实可用的情况下与环境交互。

As mentioned, org.springframework.context.ApplicationContext ApplicationContext
extends EnvironmentCapable, and thus exposes a getEnvironment()method; however,
ConfigurableApplicationContextredefines getEnvironment()and narrows the signature to return a ConfigurableEnvironment. The effect is that an Environment object is ‘read-only’ until it is being accessed from a ConfigurableApplicationContext, at which point it too may be configured.

第三段:ApplicationContext继承了EnvironmentCapable,并暴露了getEnvironment()方法;然而,ConfigurableApplicationContext重新定义了getEnvironment()方法并返回ConfigurableEnvironment。这样做的效果是,环境对象时只读的,直到从ConfigurableApplicationContext访问它,此时它是可以被配置的。

总结:EnvironmentCapable是ApplicationContext的其中一个父接口。只要获取到ApplicationContext,就可以借助父类EnvironmentCapable的getEnvironment()方法获取到Environment。

3.1.2.4 MessageSource

ApplicationContext继承了MessageSource。

Strategy interface for resolving messages, with support for the parameterization and internationalization of such messages.

第一段:MessageSource是用于解析消息的策略接口,支持此类消息的参数化和国际化

Spring provides two out-of-the-box implementations for production:

  • org.springframework.context.support.ResourceBundleMessageSource: built on top of the standard java.util.ResourceBundle, sharing its limitations.
  • org.springframework.context.support.ReloadableResourceBundleMessageSource: highly configurable, in particular with respect to reloading message definitions.

第二段:SpringFramework提供了两个开箱即用的实现:

  • ResourceBundleMessageSource :建立在标准的java.util.ResourceBundle之上,共享它的局限性。
  • ReloadableResourceBundleMessageSource :高度可配置,特别是在重新加载消息定义方面。

总结: MessageSource是ApplicationContext的其中一个父接口,用于实现ApplicationContext的国际化支持。当调用ApplicationContext的国际化相关方法时,内部直接将调用转发到MessageSource的落地实现类对象上。

3.1.2.5 ApplicationEventPublisher

从类名可知,ApplicationEventPublisher是一个事件发布器。ApplicationContext继承了ApplicationEventPublisher。

在SpringFramework内部,ApplicationContext是观察者模式中广播器的角色:ApplicationContext实现了ApplicationEventPublisher接口,因此具有事件广播器发布事件的能力;ApplicationContext还组合了ApplicationEventMulticaster,因此具有事件广播器广播事件的能力。

3.1.2.6 ResourcePatternResolver

ApplicationContext继承了ResourcePatternResolver。

Strategy interface for resolving a location pattern (for example, an Ant-style path pattern) into Resource objects.

第一段:ResourcePatternResolver是一个根据特定路径解析资源文件的策略接口(例如Ant风格的路径)。

This is an extension to the org.springframework.core.io.ResourceLoaderinterface. A passed-in ResourceLoader (for example, an org.springframework.context.ApplicationContextpassed in via org.springframework.context.ResourceLoaderAwarewhen running in a context) can be checked whether it implements this extended interface too.

第二段:这是ResourceLoader接口的扩展。可以检查传入的ResourceLoader是否也实现了这个扩展接口(例如在上下文中运行时通过ResourceLoaderAware传入的ApplicationContext)。

PathMatchingResourcePatternResolveris a standalone implementation that is usable outside an ApplicationContext, also used by ResourceArrayPropertyEditorfor populating Resource array bean properties.

第三段:PathMatchingResourcePatternResolver是一个独立的实现,可以在ApplicationContext之外调用,ResourceArrayPropertyEditor也使用它来填充资源数组Bean属性。

Can be used with any sort of location pattern (e.g. “/WEB-INF/*-context.xml”): Input patterns have to match the strategy implementation. This interface just specifies the conversion method rather than a specific pattern format.

第四段:可以用于任何类型的路径模式(例如"/WEB-INF/*-context.xml"):输入模式必须与策略实现匹配。这个接口只是指定转换方法,而不是指定特定的模式格式。

This interface also suggests a new resource prefix “classpath*:” for all matching resources from the class path. Note that the resource location is expected to be a path without placeholders in this case (e.g. “/beans.xml”); JAR files or classes directories can contain multiple files of the same name.

第五段:这个接口还建议为类路径中的所有匹配资源添加一个新的资源前缀“classpath*:”。请注意,在这种情况下,资源位置应该是一个没有占位符的路径(例如“/beans.xml”);JAR文件或类目录可以包含多个同名文件。

总结:从类名可以将ResourcePatternResolver理解为“资源模式解析器”,其作用是根据特定的路径解析资源文件,支持Ant形式的带星号的路径解析。ResourcePatternResolver可以根据特殊的路径返回多个匹配到的资源文件。借助该机制,ApplicationContext可以将所需要的资源文件加载到应用程序中,从而完成功能配置、属性赋值等工作。

拓展:Ant路径匹配写法

  • /WEB-INF/*.xml :匹配/WEB-INF目录下的任意XML文件。
  • /WEB-INF/**/beans-*.xml :匹配/WEB-INF目录下任意层级目录的beans-开头的XML文件。
  • /**/*.xml :匹配任意XML文件。
3.1.2.7 AbstractApplicationContext

介绍完接口,接下来是ApplicationContext的几个重要实现类。借助IDEA的结构图,可以看到,ApplicationContext的实现类中,AbstractApplicationContext显得尤为重要:

ApplicationContext的实现类

实际上AbstractApplicationContext定义和实现了绝大部分应用上下文的特性和功能。

Abstract implementation of the org.springframework.context.ApplicationContextinterface. Doesn’t mandate the type of storage used for configuration; simply implements common context functionality. Uses the Template Method design pattern, requiring concrete subclasses to implement abstract methods.

第一段:ApplicationContext接口的抽象实现类。它只是简单地实现了应用上下文的基本功能,并不强制约束配置的承载形式(XML、注解驱动等)。内部使用模板方法设计模式规范整体功能逻辑,具体实现由子类负责。

In contrast to a plain BeanFactory, an ApplicationContext is supposed to detect special beans defined in its internal bean factory: Therefore, this class automatically registers BeanFactoryPostProcessors, BeanPostProcessors, and ApplicationListenerswhich are defined as beans in the context.

第二段:与普通的BeanFactory相比,ApplicationContext能够检测在其内部BeanFactory中定义的特殊Bean。这个类自动注册了BeanFactoryPostProcessors、BeanPostProcessors喝ApplicationListeners,这些都被定义为上下文中的Bean。

A org.springframework.context.MessageSourcemay also be supplied as a bean in the context, with the name “messageSource”; otherwise, message resolution is delegated to the parent context. Furthermore, a multicaster for application events can be supplied as an “applicationEventMulticaster” bean of type org.springframework.context.event.ApplicationEventMulticasterin the context; otherwise, a default multicaster of type org.springframework.context.event.SimpleApplicationEventMulticasterwill be used.

第三段:ApplicationContext实现了国际化接口MessageSource,否则消息解析将委托给父级上下文;实现了事件广播器接口ApplicationEventMulticaster,否则将使用默认的事件广播器接口SimpleApplicationEventMulticaster。

Implements resource loading by extending org.springframework.core.io.DefaultResourceLoader. Consequently treats non-URL resource paths as class path resources (supporting full class path resource names that include the package path, e.g. “mypackage/myresource.dat”), unless the getResourceByPathmethod is overridden in a subclass.

第四段:通过继承DefaultResourceLoader实现资源加载。因此将非URL资源路径视为类路径资源(支持包含包路径的完整类路径资源名,例如“mypackage/myresource.dat”),除非getResourceByPath方法在子类中被重写。

总结:AbstractApplicationContext只构建功能抽象,实现了国际化接口、事件广播器接口,加载资源文件的策略默认是直接继承DefaultResourceLoader的策略。

3.1.2.8 GenericApplicationContext

Generic ApplicationContext implementation that holds a single internal org.springframework.beans.factory.support.DefaultListableBeanFactoryinstance and does not assume a specific bean definition format. Implements the org.springframework.beans.factory.support.BeanDefinitionRegistryinterface in order to allow for applying any bean definition readers to it.

第一段:GenericApplicationContext实现类拥有一个内部DefaultListableBeanFactory实例,并且不采用特定的Bean定义格式。它还实现了BeanDefinitionRegistry接口,以便允许将任何Bean定义读取器应用于该容器中。

重点:

  • GenericApplicationContext组合了BeanFactory,因此ApplicationContext并不是继承自BeanFactory容器,而是组合了BeanFactory;
  • GenericApplicationContext实现了BeanDefinitionRegistry接口,所以Bean的定义信息可以通过GenericApplicationContext注册到容器中。

Typical usage is to register a variety of bean definitions via the org.springframework.beans.factory.support.BeanDefinitionRegistryinterface and then call refresh()to initialize those beans with application context semantics (handling org.springframework.context.ApplicationContextAware, auto-detecting BeanFactoryPostProcessors, etc).

第二段:典型用法是通过BeanDefinitionRegistry结构注册各种Bean定义信息,然后调用refresh()方法在应用上下文语义中初始化这些bean对象(处理ApplicationContextAware,自动检测BeanFactoryPostProcessors等)。

注意,在GenericApplicationContext中实现的Bean定义注册方法registerBeanDefinition方法,在底层是调用DefaultListableBeanFactory的registerBeanDefinition方法,说明它对此没有做任何扩展,仅仅是委托机制的体现。

In contrast to other ApplicationContext implementations that create a new internal BeanFactory instance for each refresh, the internal BeanFactory of this context is available right from the start, to be able to register bean definitions on it. refresh()may only be called once.

第三段:与其他的「为每次刷新都创建一个新的内部BeanFactory实例」 的ApplicationContext实现类相比,此上下文中的内部BeanFactory从一开始就可以使用,以便能够在其上注册Bean定义。refresh()方法只能被调用一次。

注意,此上下文中的内部BeanFactory从一开始就可以使用,是因为在GenericApplicationContext的构造方法中就已经初始化完毕

public GenericApplicationContext() {
    // 内置的BeanFactory在构造方法中被初始化
    this.beanFactory = new DefaultListableBeanFactory();
}

@Override
protected final void refreshBeanFactory() throws IllegalStateException {
    if (!this.refreshed.compareAndSet(false, true)) {
        // 利用CAS,确保refresh()方法只能被调用一次
        throw new IllegalStateException("GenericApplicationContext does not support multiple refresh attempts: just call 'refresh' once");
    }
    this.beanFactory.setSerializationId(getId());
}

For the typical case of XML bean definitions, simply use ClassPathXmlApplicationContextor FileSystemXmlApplicationContext, which are easier to set up - but less flexible, since you can just use standard resource locations for XML bean definitions, rather than mixing arbitrary bean definition formats. The equivalent in a web environment is org.springframework.web.context.support.XmlWebApplicationContext.

第四段:对于XML Bean定义的典型情况,只需使用ClassPathXmlApplicationContext或FileSystemXmlApplicationContext,因为它们更易于设置(但灵活性较差,只能从标准的资源配置文件中读取XML Bean定义,而不能混合使用任意Bean定义的格式)。在Web环境中,GenericApplicationContext的替代方案是XmlWebApplicationContext。

3.1.2.9 AnnotationConfigApplicationContext

Standalone application context, accepting component classes as input in particular @Configuration-annotated classes, but also plain @Componenttypes and JSR-330 compliant classes using javax.injectannotations.

第一段:AnnotationConfigApplicationContext是一个独立的ApplicationContext,它接受组件类作为输入(特别是使用@Configuration注解标注的类),还可以使用普通的@Component类和符合JSR-330规范(使用javax.inject包的注解)的类。

Allows for registering classes one by one using register(Class...)as well as for classpath scanning using scan(String...).

第二段:允许使用register(Class…)方法直接传入指定的配置类,以及使用scan(String…)方法进行类路径的包扫描。

In case of multiple @Configurationclasses, @Beanmethods defined in later classes will override those defined in earlier classes. This can be leveraged to deliberately override certain bean definitions via an extra @Configurationclass.

第三段:对于多个@Configuration类,在后面的类中定义的@Bean方法将覆盖在先前的类中定义的这些方法。这可以通过一个额外的@Configuration类来故意覆盖某些Bean定义。

总结:AnnotationConfigApplicationContext是SpringFramework中最常使用的注解驱动IOC容器,对注入被@Configuration标注的类很友好。它本身继承GenericApplicationContext,因此也只能刷新一次。

3.1.2.10 AbstractRefreshableConfigApplicationContext

AbstractRefreshableApplicationContextsubclass that adds common handling of specified config locations. Serves as base class for XML-based application context implementations such as ClassPathXmlApplicationContextand FileSystemXmlApplicationContext, as well as org.springframework.web.context.support.XmlWebApplicationContext.

AbstractRefreshableApplicationContext子类添加了对指定的配置文件路径的通用处理功能,用作基于XML配置文件的IOC容器的基类,它的落地实现有ClassPathXmlApplicationContext和FileSystemXmlApplicationContext,还有支持Web环境的XmlWebApplicationContext。

但要注意的是,AbstractRefreshableApplicationContext作为基于XML配置文件的IOC容器,SpringBoot已不再使用,SpringBoot扩展出的IOC容器全部都是基于注解驱动的。

基于XML配置文件的IOC容器有一个特殊的特性:可重复刷新。并且IOC容器会在加载配置文件时才初始化内部的BeanFactory,然后是解析配置文件、注册bean对象等动作。

3.1.3 选择ApplicationContext而不是BeanFactory

在实际项目开发中,应该选择ApplicationContext还是BeanFactory的问题,官方文档给出了一种观点:

You should use an ApplicationContextunless you have a good reason for not doing so, with GenericApplicationContextand its subclass AnnotationConfigApplicationContextas the common implementations for custom bootstrapping. These are the primary entry points to Spring’s core container for all common purposes: loading of configuration files, triggering a classpath scan, programmatically registering bean definitions and annotated classes, and (as of 5.0) registering functional bean definitions.

你应该使用ApplicationContext,除非你有好的理由不用它。一般情况下,我们推荐将GenericApplicationContext及其子类AnnotationConfigApplicationContext作为自定义引导的常见实现。这些实现类是用于所有常见目的的SpringFramework核心容器主要入口点:加载配置文件,出发类路径扫描,编程式注册Bean定义和带注解的类,以及(从5.0版本开始)注册功能性Bean的定义。

这段话下面还提供了一张表,对比了BeanFactory和ApplicationContext的不同特性:

BeanFactory和ApplicationContext的不同特性
第一项到第六项分别是:Bean的实例化和属性注入、生命周期管理、Bean后置处理器的支持、BeanFactory后置处理器的支持、消息转换服务(国际化)、事件发布机制(事件驱动)。可见,BeanFactory仅支持第一项Bean的实例化和属性注入,ApplicationContext支持全部六项。

因此,ApplicationContext相较于BeanFactory功能更强大,这也解释了为什么日常开发中都是使用ApplicationContext而很少使用BeanFactory。

3.1.4 总结

至此,可以总结一下ApplicationContext的特性:

  • ApplicationContext :根接口
  • ConfigurableApplicationContext :可写功能
  • EnvironmentCapable :获取Environment组件
  • MessageSource :国际化支持
  • ApplicationEventPublisher :事件发布
  • ResourcePatternResolver :资源解析
  • AbstractApplicationContext :构建功能抽象
  • GenericApplicationContext :注解驱动
  • AnnotationConfigApplicationContext :注解驱动
  • AbstractRefreshableConfigApplicationContext :XML配置文件驱动

将SpringFramework的两部分——BeanFactory和ApplicationContext接口及其子类合在一起看,利用IDEA生成这两个接口的继承关系图:

BeanFactory和ApplicationContext
上图的左侧主要是ApplicationContext的父级接口及实现类,右侧主要是BeanFactory及其子接口。ApplicationContext继承了ListableBeanFactory、HierarchicalBeanFactory,从而使两者联系起来。

······

本节完,更多内容请查阅分类专栏:SpringBoot源码解读与原理分析

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/376607.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

当我们一起走过 2023|Apache Doris 年度时刻盘点

2024 年的第一个月已经彻底过去,2023 年的回顾总结才姗姗来迟。 在过去一年的大多数时间里,我们一直处于忙碌的状态中,紧锣密鼓的代码研发、高速推进的版本迭代、行程紧密的全国之行,众多社区用户与开发者皆是见证。 越是忙碌&a…

Yearning审核平台本地安装配置并结合内网穿透实现远程访问

文章目录 前言1. Linux 部署Yearning2. 本地访问Yearning3. Linux 安装cpolar4. 配置Yearning公网访问地址5. 公网远程访问Yearning管理界面6. 固定Yearning公网地址 前言 Yearning 简单, 高效的MYSQL 审计平台 一款MYSQL SQL语句/查询审计工具,为DBA与开发人员使用…

vector类的模拟实现

实现基本的vector框架 参考的是STL的一些源码&#xff0c;实现的vector也是看起来像是一个简略版的&#xff0c;但是看完能对vector这个类一些接口函数更好的认识。 我们写写成员变量&#xff0c;先来看看STL的成元变量是那些 namespace tjl {template<class T>class …

【C语言|数据结构】数据结构顺序表

目录 一、数据结构 1.1概念 1.2总结 1.3为什么需要数据结构&#xff1f; 二、顺序表 1.顺序表的概念及结构 1.1线性表 2.顺序表分类 2.1顺序表和数组的区别 2.2顺序表的分类 2.2.1静态顺序表 2.2.1.1概念 2.2.1.2缺陷 2.2.2动态顺序表 三、动态顺序表的实现 3.1新…

Pandas文本数据处理技术指南—从查找到时间序列分析【第66篇—python:文本数据处理】

文章目录 Pandas文本数据处理技术指南引言 1. 查找文本数据2. 替换文本数据3. 拼接文本数据4. 正则表达式操作5. 虚拟变量6. 处理缺失值7. 分割文本数据8. 字符串处理方法9. 文本数据的合并与连接10. 文本数据的排序11. 文本数据的统计分析12. 文本数据的分组与聚合13. 文本数据…

使用Softing edgeConnector模块将云轻松连接到Siemens PLC

一 工业边缘的连接解决方案 云服务提供商 (CSP) 引入了服务和功能&#xff0c;以简化基于云的工业物联网解决方案的实施。Azure Industrial IoT Platform或AWS IoT SiteWise支持标准协议和接口&#xff0c;例如OPC UA或MQTT。但是&#xff0c;如果您希望在典型的旧改项目中连接…

【代理模式】

定义&#xff1a;代理模式是一种结构型设计模式&#xff0c;它允许我们创建一个代理对象&#xff0c;用于控制对另一个对象的访问。 代理对象充当了被代理对象&#xff08;目标对象&#xff09;的代表&#xff0c;与被代理对象实现相同的接口&#xff0c;从而实现对被代理对象…

【PowerShell】修改Windows网络配置的常用命令

PowerShell&#xff08;PS&#xff09;是一种强大的任务自动化和管理框架&#xff0c;具有丰富的命令和语法&#xff0c;可以用于编写脚本来管理Windows操作系统和其他应用程序。它的开放式架构和跨平台支持使得它成为一个灵活和可扩展的工具。 在网络配置方面&#xff0c;Powe…

C++ 日期计算器

日期计算器 概要 Date类的规划Date类的实现Date 构造函数Date 拷贝构造函数~Date 析构函数GetMonthDay 求某年某月的天数operator 赋值操作符重载operator 加等操作符重载operator 加号操作符重载operator- 减等操作符重载operator- 减法操作符重载 &#xff08;日期 - 天数&am…

分享66个行业PPT,总有一款适合您

分享66个行业PPT&#xff0c;总有一款适合您 66个行业PPT下载链接&#xff1a;https://pan.baidu.com/s/1kcUOfR_xtH9CAJC12prcTw?pwd8888 提取码&#xff1a;8888 Python采集代码下载链接&#xff1a;采集代码.zip - 蓝奏云 学习知识费力气&#xff0c;收集整理更不易。知…

算法学习——华为机考题库3(HJ21 - HJ25)

算法学习——华为机考题库3&#xff08;HJ21 - HJ30&#xff09; HJ21 简单密码 描述 现在有一种密码变换算法。 九键手机键盘上的数字与字母的对应&#xff1a; 1–1&#xff0c; abc–2, def–3, ghi–4, jkl–5, mno–6, pqrs–7, tuv–8 wxyz–9, 0–0&#xff0c;把密码…

Swift Combine 发布者订阅者操作者 从入门到精通二

Combine 系列 Swift Combine 从入门到精通一 1. Combine核心概念 你只需要了解几个核心概念&#xff0c;就能使用好 Combine&#xff0c;但理解它们非常重要。 这些概念中的每一个都通过通用协议反映在框架中&#xff0c;以将概念转化为预期的功能。 这些核心概念是&#x…

Cocos creator 3.x 刚体组件碰撞无效

Cocos creator 3.x 刚体组件碰撞无效 问题描述&#xff1a;只有一个circleCollider2D时&#xff0c;可以在碰撞时正确输出结果&#xff0c;但是当我在外围加了一个circle之后&#xff0c;期望character进入圆圈范围时就触发方法&#xff0c;此时原代码失效 import { _decorat…

简单说网络:TCP+UDP

TCP和UPD: (1)都工作在传输层 (2)目的都是在程序之中传输数据 (3)数据可以是文本、视频或者图片(对TCP和UDP来说都是一堆二进制数没有太大区别) 一、区别:一个基于连接一个基于非连接 将人与人之间的通信比喻为进程和进程之前的通信:基本上有两种方式(1)写信;(2)打电话;这…

【51单片机】实现一个动静态数码管显示项目(前置知识铺垫,代码&图演示)(5)

前言 大家好吖&#xff0c;欢迎来到 YY 滴单片机 系列 &#xff0c;热烈欢迎&#xff01; 本章主要内容面向接触过单片机的老铁 主要内容含&#xff1a; 欢迎订阅 YY滴C专栏&#xff01;更多干货持续更新&#xff01;以下是传送门&#xff01; YY的《C》专栏YY的《C11》专栏YY…

Redis的数据类型Hash使用场景实战

Redis的数据类型Hash使用场景 常见面试题&#xff1a;redis在你们项目中是怎么用的&#xff0c;除了String数据类型还使用什么数据类型&#xff1f; 怎么保证缓存和数据一致性等问题… Hash模型使用场景 知识回顾&#xff1a; redisTemplate.opsForHash() 方法是 Redis 的 …

QAnything之BCEmbedding技术路线

QAnything和BCEmbedding简介 QAnything[github]是网易有道开源的检索增强生成式应用&#xff08;RAG&#xff09;项目&#xff0c;在有道许多商业产品实践中已经积累丰富的经验&#xff0c;比如有道速读和有道翻译。QAnything是一个支持任意格式文件或数据库的本地知识库问答系…

python的数据类型

&#x1f388;srting&#xff08;字符串&#xff09;&#xff1a; 操作符&#xff1a; &#xff1a;字符串连接 aabc befg print(ab) #输出 abcdefg * : 重复输出字符串 aabc print(a*3) #输出 abcabcabc [ : ]:截取字符串中的一部分&#xff0c;遵循左闭右开的原则&am…

vue实现购物车案例

话不多说&#xff0c;先上效果图。 安装elementui组件库&#xff0c;可直接食用。 <template><div><!-- 购物车部分 --><el-container><el-header><h1>购物车案例一条龙</h1></el-header><el-main><!-- 折叠面板…