SPRING10_getBean源码详细解读、流程图

文章目录

  • ①. getBean方法的入口-DefaultListableBeanFactory
  • ②. DefaultListableBeanFactory调用getBean
  • ③. 进入到doGetBean方法
  • ④. getSingleton三级缓存方法
  • ⑤. getSingleton()方法分析
  • ⑥. createBean创建对象方法
  • ⑦. 对象创建、属性赋值、初始化
  • ⑧. getBean最详细流程图

①. getBean方法的入口-DefaultListableBeanFactory

  • ①. getBean方法的入口:在Spring中,getBean方法的入口通常位于BeanFactory或ApplicationContext接口的实现类中。最常见的是DefaultListableBeanFactory类,它是Spring容器的核心实现,如下是三个API
// 根据name获取bean	
@Override
public Object getBean(String name) throws BeansException {return doGetBean(name, null, null, false);
}// 根据name获取bean,如果获取到的bean和指定类型不匹配,则抛出异常
@Override
public <T> T getBean(String name, Class<T> requiredType) throws BeansException {return doGetBean(name, requiredType, null, false);
}// 根据name获取bean,如果是一个有参构造器生成的bean,则将参数对象注入到构造器中
@Override
public Object getBean(String name, Object... args) throws BeansException {return doGetBean(name, null, args, false);
}

在这里插入图片描述

②. DefaultListableBeanFactory调用getBean

  • ②. DefaultListableBeanFactory中先获取到所有的bean的名称,for循环调用getBean方法
DefaultListableBeanFactorypublic void preInstantiateSingletons() throws BeansException {if (logger.isTraceEnabled()) {logger.trace("Pre-instantiating singletons in " + this);}// Iterate over a copy to allow for init methods which in turn register new bean definitions.// While this may not be part of the regular factory bootstrap, it does otherwise work fine.List<String> beanNames = new ArrayList<>(this.beanDefinitionNames);// Trigger initialization of all non-lazy singleton beans...for (String beanName : beanNames) {RootBeanDefinition bd = getMergedLocalBeanDefinition(beanName);// 是非抽象的并且是单例的并且不是懒加载的if (!bd.isAbstract() && bd.isSingleton() && !bd.isLazyInit()) {// 如果是FactoryBean执行下面逻辑(如果是实现了FactoryBean,isFactoryBean的标识为true)if (isFactoryBean(beanName)) {Object bean = getBean(FACTORY_BEAN_PREFIX + beanName);// beanName = & + beanNameif (bean instanceof FactoryBean) {FactoryBean<?> factory = (FactoryBean<?>) bean;boolean isEagerInit;if (System.getSecurityManager() != null && factory instanceof SmartFactoryBean) {isEagerInit = AccessController.doPrivileged((PrivilegedAction<Boolean>) ((SmartFactoryBean<?>) factory)::isEagerInit,getAccessControlContext());}else {isEagerInit = (factory instanceof SmartFactoryBean &&((SmartFactoryBean<?>) factory).isEagerInit());}if (isEagerInit) {getBean(beanName);}}}else {// 不是FactoryBean执行下面逻辑,普通的单实例非懒加载beangetBean(beanName);}}}
}
AbstractBeanFactory@Override
public Object getBean(String name) throws BeansException {return doGetBean(name, null, null, false);
}

③. 进入到doGetBean方法

  • ③. 进入到doGetBean方法
  1. transformedBeanName,处理别名BeanName、处理带&符的工厂BeanName。
  2. getSingleton,先尝试从缓存中获取Bean实例,这个位置就是三级缓存解决循环依赖的方法(后面重点说)</font
  3. getObjectForBeanInstance,如果sharedInstance是普通的Bean实例,则下面的方法会直接返回。另外sharedInstance是工厂Bean类型,则需要获取getObject方法,可以参考关于FactoryBean的实现类。
  4. isPrototypeCurrentlyInCreation,循环依赖有三种,setter注入、多实例和构造函数,Spring只能解决setter注入,所以这里是Prototype则会抛出异常。
  5. getParentBeanFactory,父bean工厂存在,当前bean不存在于当前bean工厂,则到父工厂查找bean实例。
  6. mbd.getDependsOn,处理使用了depends-on注解的依赖创建bean实例。getBean(dep),加载depends-on依赖dep是depends-on缩写
  7. mbd.isSingleton(),创建单例bean实例,这里的sharedInstance = getSingleton(beanName, () -> {})很重要</font
  8. mbd.isPrototype(),创建其他类型的bean实例
protected <T> T doGetBean(String name, @Nullable Class<T> requiredType, @Nullable Object[] args, boolean typeCheckOnly)throws BeansException {//处理别名BeanName、处理带&符的工厂BeanName,工厂beanName带了&xxx 最后会变成xxxString beanName = transformedBeanName(name);Object beanInstance;// Eagerly check singleton cache for manually registered singletons.// 先检查单实例bean缓存Object sharedInstance = getSingleton(beanName);if (sharedInstance != null && args == null) {if (logger.isTraceEnabled()) {if (isSingletonCurrentlyInCreation(beanName)) {logger.trace("Returning eagerly cached instance of singleton bean '" + beanName +"' that is not fully initialized yet - a consequence of a circular reference");}else {logger.trace("Returning cached instance of singleton bean '" + beanName + "'");}}beanInstance = getObjectForBeanInstance(sharedInstance, name, beanName, null);}else {//默认第一次获取组件都会进入到else环节,如果第一次获取肯定是没有的// Fail if we're already creating this bean instance:// We're assumably within a circular reference.// 如果是一个多实例bean,抛出异常if (isPrototypeCurrentlyInCreation(beanName)) {throw new BeanCurrentlyInCreationException(beanName);}// 拿到整个bean工厂,拿到父工厂;看父工厂有没有,如果有从父工厂去获取 Check if bean definition exists in this factory.BeanFactory parentBeanFactory = getParentBeanFactory();if (parentBeanFactory != null && !containsBeanDefinition(beanName)) {// Not found -> check parent.String nameToLookup = originalBeanName(name);if (parentBeanFactory instanceof AbstractBeanFactory) {return ((AbstractBeanFactory) parentBeanFactory).doGetBean(nameToLookup, requiredType, args, typeCheckOnly);}else if (args != null) {// Delegation to parent with explicit args.return (T) parentBeanFactory.getBean(nameToLookup, args);}else if (requiredType != null) {// No args -> delegate to standard getBean method.return parentBeanFactory.getBean(nameToLookup, requiredType);}else {return (T) parentBeanFactory.getBean(nameToLookup);}}if (!typeCheckOnly) {// 标记当前bean已经被创建,用来阻止多线程引用的markBeanAsCreated(beanName);}StartupStep beanCreation = this.applicationStartup.start("spring.beans.instantiate").tag("beanName", name);try {if (requiredType != null) {beanCreation.tag("beanType", requiredType::toString);}RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);checkMergedBeanDefinition(mbd, beanName, args);// Guarantee initialization of beans that the current bean depends on.String[] dependsOn = mbd.getDependsOn();if (dependsOn != null) {// 看有没有依赖其他Bean,如果有先获取其他的那个Beanfor (String dep : dependsOn) {if (isDependent(beanName, dep)) {throw new BeanCreationException(mbd.getResourceDescription(), beanName,"Circular depends-on relationship between '" + beanName + "' and '" + dep + "'");}registerDependentBean(dep, beanName);try {getBean(dep);}catch (NoSuchBeanDefinitionException ex) {throw new BeanCreationException(mbd.getResourceDescription(), beanName,"'" + beanName + "' depends on missing bean '" + dep + "'", ex);}}}// Create bean instance. 创建Bean试连if (mbd.isSingleton()) {sharedInstance = getSingleton(beanName, () -> {try {return createBean(beanName, mbd, args);}catch (BeansException ex) {// Explicitly remove instance from singleton cache: It might have been put there// eagerly by the creation process, to allow for circular reference resolution.// Also remove any beans that received a temporary reference to the bean.destroySingleton(beanName);throw ex;}});// 看当前bean是否是使用了beanFactorybeanInstance = getObjectForBeanInstance(sharedInstance, name, beanName, mbd);}else if (mbd.isPrototype()) {// It's a prototype -> create a new instance.Object prototypeInstance = null;try {beforePrototypeCreation(beanName);prototypeInstance = createBean(beanName, mbd, args);}finally {afterPrototypeCreation(beanName);}beanInstance = getObjectForBeanInstance(prototypeInstance, name, beanName, mbd);}else {String scopeName = mbd.getScope();if (!StringUtils.hasLength(scopeName)) {throw new IllegalStateException("No scope name defined for bean ´" + beanName + "'");}Scope scope = this.scopes.get(scopeName);if (scope == null) {throw new IllegalStateException("No Scope registered for scope name '" + scopeName + "'");}try {Object scopedInstance = scope.get(beanName, () -> {beforePrototypeCreation(beanName);try {return createBean(beanName, mbd, args);}finally {afterPrototypeCreation(beanName);}});beanInstance = getObjectForBeanInstance(scopedInstance, name, beanName, mbd);}catch (IllegalStateException ex) {throw new ScopeNotActiveException(beanName, scopeName, ex);}}}catch (BeansException ex) {beanCreation.tag("exception", ex.getClass().toString());beanCreation.tag("message", String.valueOf(ex.getMessage()));cleanupAfterBeanCreationFailure(beanName);throw ex;}finally {beanCreation.end();}}return adaptBeanInstance(name, beanInstance, requiredType);
}

④. getSingleton三级缓存方法

  • ④. Object sharedInstance = getSingleton(beanName,第一次进来的时候,会直接返回null
  1. 一级缓存 - singletonObjects
  2. 二级缓存 - earlySingletonObjects,当前bean已经创建,未进行实例化
  3. 三级缓存 - singletonFactories,用来保存BeanName和创建bean的工厂之间的关系
	/** * 一级缓存* Cache of singleton objects: bean name --> bean instance */private final Map<String, Object> singletonObjects = new ConcurrentHashMap<>(256);/** * 三级缓存* 用来保存BeanName和创建bean的工厂之间的关系* Cache of singleton factories: bean name --> ObjectFactory */private final Map<String, ObjectFactory<?>> singletonFactories = new HashMap<>(16);/** * 二级缓存* 保存BeanName和创建bean实例之间的关系,与singletonFactories的不同之处在于,当一个单例bean被放到这里之后,那么当bean还在创建过程中* 就可以通过getBean方法获取到,可以方便进行循环依赖的检测* Cache of early singleton objects: bean name --> bean instance */private final Map<String, Object> earlySingletonObjects = new HashMap<>(16);public Object getSingleton(String beanName) { // allowEarlyReference 允许早期引用(循环依赖的核心)return getSingleton(beanName, true);}@Nullableprotected Object getSingleton(String beanName, boolean allowEarlyReference) {// 先检查单列缓存池,获取当前对象 Quick check for existing instance without full singleton lockObject singletonObject = this.singletonObjects.get(beanName);// 先看单例池有没有 并且 是否正在创建if (singletonObject == null && isSingletonCurrentlyInCreation(beanName)) {// 如果当前bean正在创建过程中,而且缓存中没有继续往下//singletonObject = this.earlySingletonObjects.get(beanName);if (singletonObject == null && allowEarlyReference) {synchronized (this.singletonObjects) {// Consistent creation of early reference within full singleton locksingletonObject = this.singletonObjects.get(beanName);if (singletonObject == null) {singletonObject = this.earlySingletonObjects.get(beanName);if (singletonObject == null) {ObjectFactory<?> singletonFactory = this.singletonFactories.get(beanName);if (singletonFactory != null) {singletonObject = singletonFactory.getObject();this.earlySingletonObjects.put(beanName, singletonObject);this.singletonFactories.remove(beanName);}}}}}}return singletonObject;}

⑤. getSingleton()方法分析

  • ⑤. public Object getSingleton(String beanName, ObjectFactory<?> singletonFactory)方法
  1. beforeSingletonCreation(beanName)会将beanName加入到singletonsCurrentlyInCreation集合中去,表示正在创建的集合
  2. singletonFactory.getObject()会调用lamda表达式的内容[这里之后要进入lamda方法流程]
  3. afterSingletonCreation(beanName)会将当前beanName从singletonsCurrentlyInCreation中移除出去
  4. addSingleton方法会将当前bean加入到singletonObjects池中去
	public Object getSingleton(String beanName, ObjectFactory<?> singletonFactory) {Assert.notNull(beanName, "Bean name must not be null");synchronized (this.singletonObjects) {Object singletonObject = this.singletonObjects.get(beanName);if (singletonObject == null) {if (this.singletonsCurrentlyInDestruction) {throw new BeanCreationNotAllowedException(beanName,"Singleton bean creation not allowed while singletons of this factory are in destruction " +"(Do not request a bean from a BeanFactory in a destroy method implementation!)");}if (logger.isDebugEnabled()) {logger.debug("Creating shared instance of singleton bean '" + beanName + "'");}beforeSingletonCreation(beanName);boolean newSingleton = false;boolean recordSuppressedExceptions = (this.suppressedExceptions == null);if (recordSuppressedExceptions) {this.suppressedExceptions = new LinkedHashSet<>();}try {// 会调用lamda表达式的内容singletonObject = singletonFactory.getObject();newSingleton = true;}catch (IllegalStateException ex) {// Has the singleton object implicitly appeared in the meantime ->// if yes, proceed with it since the exception indicates that state.singletonObject = this.singletonObjects.get(beanName);if (singletonObject == null) {throw ex;}}catch (BeanCreationException ex) {if (recordSuppressedExceptions) {for (Exception suppressedException : this.suppressedExceptions) {ex.addRelatedCause(suppressedException);}}throw ex;}finally {if (recordSuppressedExceptions) {this.suppressedExceptions = null;}afterSingletonCreation(beanName);}if (newSingleton) {addSingleton(beanName, singletonObject);}}return singletonObject;}}protected void addSingleton(String beanName, Object singletonObject) {synchronized (this.singletonObjects) {this.singletonObjects.put(beanName, singletonObject);this.singletonFactories.remove(beanName);this.earlySingletonObjects.remove(beanName);this.registeredSingletons.add(beanName);}}

⑥. createBean创建对象方法

  • ⑥. 进入到createBean(beanName, mbd, args);lamda流程,最重要的是doCreateBean方法,进入到创建对象流程中
	protected Object createBean(String beanName, RootBeanDefinition mbd, @Nullable Object[] args)throws BeanCreationException {// 提前给一个机会,去返回组件的代理对象(aop也没有在这里操作) Give BeanPostProcessors a chance to return a proxy instead of the target bean instance.Object bean = resolveBeforeInstantiation(beanName, mbdToUse);if (bean != null) {return bean;}......Object beanInstance = doCreateBean(beanName, mbdToUse, args);if (logger.isTraceEnabled()) {logger.trace("Finished creating instance of bean '" + beanName + "'");}return beanInstance;}

⑦. 对象创建、属性赋值、初始化

  • ⑦. doCreateBean方法详解
  1. 利用无参构造方法创建实例
  2. earlySingletonExposure表示:当前对象是单实列、并且singletonsCurrentlyInCreation中存在这个beanName,我们在上面的步骤中已经加入到了singletonsCurrentlyInCreation集合中了
  3. addSingletonFactory方法会将beanName加入到三级缓存singletonFactories中去
  4. populateBean进行属性的赋值,@Autowired发生在这里
  5. initializeBean初始化bean
protected Object doCreateBean(String beanName, RootBeanDefinition mbd, @Nullable Object[] args)throws BeanCreationException {// Instantiate the bean.BeanWrapper instanceWrapper = null;if (mbd.isSingleton()) {//是否单例instanceWrapper = this.factoryBeanInstanceCache.remove(beanName);}if (instanceWrapper == null) {// 创建Bean的实列,默认使用无参构造创建对象instanceWrapper = createBeanInstance(beanName, mbd, args);}Object bean = instanceWrapper.getWrappedInstance();Class<?> beanType = instanceWrapper.getWrappedClass();if (beanType != NullBean.class) {mbd.resolvedTargetType = beanType;}//允许MergedBeanDefinitionPostProcessor.postProcessMergedBeanDefinition再来修改下BeanDefinition Allow post-processors to modify the merged bean definition.synchronized (mbd.postProcessingLock) {if (!mbd.postProcessed) {try {applyMergedBeanDefinitionPostProcessors(mbd, beanType, beanName);}catch (Throwable ex) {throw new BeanCreationException(mbd.getResourceDescription(), beanName,"Post-processing of merged bean definition failed", ex);}mbd.postProcessed = true;}}// Eagerly cache singletons to be able to resolve circular references// even when triggered by lifecycle interfaces like BeanFactoryAware.boolean earlySingletonExposure = (mbd.isSingleton() && this.allowCircularReferences &&isSingletonCurrentlyInCreation(beanName));if (earlySingletonExposure) {if (logger.isTraceEnabled()) {logger.trace("Eagerly caching bean '" + beanName +"' to allow for resolving potential circular references");}addSingletonFactory(beanName, () -> getEarlyBeanReference(beanName, mbd, bean));}// Initialize the bean instance.Object exposedObject = bean;try {// 给创建好的对象每个属性进行赋值,@Autowired发生在这里populateBean(beanName, mbd, instanceWrapper);// 初始化beanexposedObject = initializeBean(beanName, exposedObject, mbd);}catch (Throwable ex) {if (ex instanceof BeanCreationException && beanName.equals(((BeanCreationException) ex).getBeanName())) {throw (BeanCreationException) ex;}else {throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Initialization of bean failed", ex);}}if (earlySingletonExposure) {Object earlySingletonReference = getSingleton(beanName, false);if (earlySingletonReference != null) {if (exposedObject == bean) {exposedObject = earlySingletonReference;}else if (!this.allowRawInjectionDespiteWrapping && hasDependentBean(beanName)) {String[] dependentBeans = getDependentBeans(beanName);Set<String> actualDependentBeans = new LinkedHashSet<>(dependentBeans.length);for (String dependentBean : dependentBeans) {if (!removeSingletonIfCreatedForTypeCheckOnly(dependentBean)) {actualDependentBeans.add(dependentBean);}}if (!actualDependentBeans.isEmpty()) {throw new BeanCurrentlyInCreationException(beanName,"Bean with name '" + beanName + "' has been injected into other beans [" +StringUtils.collectionToCommaDelimitedString(actualDependentBeans) +"] in its raw version as part of a circular reference, but has eventually been " +"wrapped. This means that said other beans do not use the final version of the " +"bean. This is often the result of over-eager type matching - consider using " +"'getBeanNamesForType' with the 'allowEagerInit' flag turned off, for example.");}}}}// Register bean as disposable.try {registerDisposableBeanIfNecessary(beanName, bean, mbd);}catch (BeanDefinitionValidationException ex) {throw new BeanCreationException(mbd.getResourceDescription(), beanName, "Invalid destruction signature", ex);}return exposedObject;}protected void addSingletonFactory(String beanName, ObjectFactory<?> singletonFactory) {Assert.notNull(singletonFactory, "Singleton factory must not be null");synchronized (this.singletonObjects) {if (!this.singletonObjects.containsKey(beanName)) {this.singletonFactories.put(beanName, singletonFactory);this.earlySingletonObjects.remove(beanName);this.registeredSingletons.add(beanName);}}}

⑧. getBean最详细流程图

在这里插入图片描述

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

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

IDEA中查询Maven项目的依赖树

在Maven项目中&#xff0c;查看项目的依赖树是一个常见的需求&#xff0c;特别是当你需要了解项目中直接或间接依赖了哪些库及其版本时。你可以通过命令行使用Maven的dependency:tree插件来做到这一点。这个命令会列出项目中所有依赖的树状结构。 打开idea项目的终端&#xff…

深入xtquant:财务数据获取与应用的实战指南

深入xtquant&#xff1a;财务数据获取与应用的实战指南 在量化交易领域&#xff0c;虽然技术分析和市场情绪分析占据了主导地位&#xff0c;但财务数据作为评估公司基本面的重要依据&#xff0c;同样不可或缺。xtquant作为一个强大的Python库&#xff0c;提供了便捷的接口来获…

windows 安装 stable diffusion

在windows上安装 stable diffusion&#xff0c;如果windows没有nvidia显卡&#xff0c;想只使用CPU可在webui-user.bat中添加命令 set COMMANDLINE_ARGS--no-half --skip-torch-cuda-test 可正常使用stable diffusion&#xff0c;但速度较慢

Kubernetes控制平面组件:APIServer 基于 引导Token 的认证机制

云原生学习路线导航页&#xff08;持续更新中&#xff09; kubernetes学习系列快捷链接 Kubernetes架构原则和对象设计&#xff08;一&#xff09;Kubernetes架构原则和对象设计&#xff08;二&#xff09;Kubernetes架构原则和对象设计&#xff08;三&#xff09;Kubernetes控…

DeepSeek 助力 Vue 开发:打造丝滑的缩略图列表(Thumbnail List)

前言&#xff1a;哈喽&#xff0c;大家好&#xff0c;今天给大家分享一篇文章&#xff01;并提供具体代码帮助大家深入理解&#xff0c;彻底掌握&#xff01;创作不易&#xff0c;如果能帮助到大家或者给大家一些灵感和启发&#xff0c;欢迎收藏关注哦 &#x1f495; 目录 Deep…

DeepSeek写俄罗斯方块手机小游戏

DeepSeek写俄罗斯方块手机小游戏 提问 根据提的要求&#xff0c;让DeepSeek整理的需求&#xff0c;进行提问&#xff0c;内容如下&#xff1a; 请生成一个包含以下功能的可运行移动端俄罗斯方块H5文件&#xff1a; 核心功能要求 原生JavaScript实现&#xff0c;适配手机屏幕 …

百问网(100ask)的IMX6ULL开发板的以太网控制器(MAC)与物理层(PHY)芯片(LAN8720A)连接的原理图分析(包含各引脚说明以及工作原理)

前言 本博文承接博文 https://blog.csdn.net/wenhao_ir/article/details/145663029 。 本博文和博文 https://blog.csdn.net/wenhao_ir/article/details/145663029 的目录是找出百问网(100ask)的IMX6ULL开发板与NXP官方提供的公板MCIMX6ULL-EVK(imx6ull14x14evk)在以太网硬件…

QT开发技术 【opencv图片裁剪,平均哈希相似度判断,以及获取游戏窗口图片】

一、图片裁剪 int CJSAutoWidget::GetHouseNo(cv::Mat matMap) {cv::imwrite(m_strPath "/Data/map.png", matMap);for (int i 0; i < 4; i){for (int j 0; j < 6; j){// 计算当前子区域的矩形cv::Rect roi(j * 20, i * 17, 20, 17);// 提取子区域cv::Mat …

TiDB 是一个分布式 NewSQL 数据库

TiDB 是一个分布式 NewSQL 数据库。它支持水平弹性扩展、ACID 事务、标准 SQL、MySQL 语法和 MySQL 协议&#xff0c;具有数据强一致的高可用特性&#xff0c;是一个不仅适合 OLTP 场景还适合 OLAP 场景的混合数据库。 TiDB是 PingCAP公司自主设计、研发的开源分布式关系型数据…

请解释 Vue 中的生命周期钩子,不同阶段触发的钩子函数及其用途是什么?

vue生命周期钩子详解&#xff08;Vue 3版本&#xff09; 一、生命周期阶段划分 Vue组件的生命周期可分为四大阶段&#xff0c;每个阶段对应特定钩子函数&#xff1a; 创建阶段&#xff1a;初始化实例并准备数据挂载阶段&#xff1a;将虚拟DOM渲染为真实DOM更新阶段&#xff…

计算机专业知识【深入理解子网中的特殊地址:为何 192.168.0.1 和 192.168.0.255 不能随意分配】

在计算机网络的世界里&#xff0c;IP 地址是设备进行通信的关键标识。对于常见的子网&#xff0c;如 192.168.0.0/24&#xff0c;我们可能会疑惑为何某些地址不能分配给主机使用。接下来&#xff0c;我们就以 192.168.0.0/24 为例&#xff0c;详细解释为何 192.168.0.1 和 192.…

软件架构设计:软件工程

一、软件工程概述 软件工程的定义 软件工程是应用系统化、规范化、可量化的方法开发、运行和维护软件。 软件工程的目标 提高软件质量、降低开发成本、缩短开发周期。 软件生命周期 瀑布模型&#xff1a;需求分析→设计→编码→测试→维护。迭代模型&#xff1a;分阶段迭代开…

mysql 学习15 SQL优化,插入数据优化,主键优化,order by优化,group by 优化,limit 优化,count 优化,update 优化

插入数据优化&#xff0c; insert 优化&#xff0c; 批量插入&#xff08;一次不超过1000条&#xff09; 手动提交事务 主键顺序插入 load 从本地一次插入大批量数据&#xff0c; 登陆时 mysql --local-infile -u root -p load data local infile /root/sql1.log into table tb…

达梦数据库针对慢SQL,收集统计信息清除执行计划缓存

前言&#xff1a;若遇到以下场景&#xff0c;大概率是SQL走错了执行计划&#xff1a; 1、一条SQL在页面上查询特别慢&#xff0c;但拿到数据库终端执行特别快 2、一条SQL在某种检索条件下查询特别慢&#xff0c;但拿到数据库终端执行特别快 此时&#xff0c;可以尝试按照下述步…

使用JWT实现微服务鉴权

目录 一、微服务鉴权 1、思路分析 2、系统微服务签发token 3、网关过滤器验证token 4、测试鉴权功能 前言&#xff1a; 随着微服务架构的广泛应用&#xff0c;服务间的鉴权与安全通信成为系统设计的核心挑战之一。传统的集中式会话管理在分布式场景下面临性能瓶颈和扩展性…

广西壮族自治区园区投促中心党委书记陶德文率团到访深兰科技

2月16日&#xff0c;广西壮族自治区园区投促中心党委书记、主任&#xff0c;自治区园区办党组成员陶德文率团来到深兰科技集团上海总部考察调研&#xff0c;并与深兰科技集团创始人、董事长陈海波等集团管理层座谈交流&#xff0c;双方围绕深兰科技人工智能项目落地广西的相关事…

基于UnrealEngine(UE5)的太空探索

视频部分可参见&#xff1a;https://www.bilibili.com/video/BV1JWA8eSEVg/ 中国 天宫号 空间站 人造卫星可视化 星链卫星可视化 小行星分布及运动轨迹可视化 月球基地 可视化 八大行星轨道 太阳系宜居带可视化 阿波罗8号拍摄的地球升起 谷神星模型及轨迹可视化 星座可视化 十…

WLAN无线2.4G/5G频段划分和可用信道

互联网各领域资料分享专区(不定期更新)&#xff1a; Sheet

使用 OpenTelemetry 和 Langtrace 的 Elastic 分发跟踪基于 RAG 的聊天机器人

作者&#xff1a;来自 Elastic Bahubali Shetti 如何使用 Elastic 观察基于 OpenAI RAG 的应用程序。使用 Langtrace 对应用程序进行检测&#xff0c;收集日志、跟踪、指标&#xff0c;并了解 LLM 在 Kubernetes 上使用 OpenTelemetry 的 Elastic Distributions 的运行情况。 目…