Spring-创建bean

news2024/11/17 6:45:54

preInstantiateSingletons

v1.0 preInstantiateSingletons

tips:最终调用getBean使用的是RootBeanDefinition进行构建的



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

		//获取所有beanDefinition的名字
		List<String> beanNames = new ArrayList<>(this.beanDefinitionNames);

		//循环
		for (String beanName : beanNames) {
			// 获取合并后的BeanDefinition,看代码V1.1
			RootBeanDefinition bd = getMergedLocalBeanDefinition(beanName);
			//如果RootBeanDefinition不是抽象BeanDefinition,是单例bean,非懒加载,则创建bean对象
			if (!bd.isAbstract() && bd.isSingleton() && !bd.isLazyInit()) {
				if (isFactoryBean(beanName)) {
					// 获取FactoryBean对象
					Object bean = getBean(FACTORY_BEAN_PREFIX + beanName);
					if (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) {
							// 创建真正的Bean对象(getObject()返回的对象)
							getBean(beanName);
						}
					}
				}
				else {
					// 创建Bean对象
					getBean(beanName);
				}
			}
		}

		// 所有的非懒加载单例Bean都创建完了后
		//找出实现了SmartInitializingSingleton接口的单例bean,并执行afterSingletonsInstantiated()方法
	
		for (String beanName : beanNames) {
			Object singletonInstance = getSingleton(beanName);
			if (singletonInstance instanceof SmartInitializingSingleton) {
				StartupStep smartInitialize = this.getApplicationStartup().start("spring.beans.smart-initialize")
						.tag("beanName", beanName);
				SmartInitializingSingleton smartSingleton = (SmartInitializingSingleton) singletonInstance;
				if (System.getSecurityManager() != null) {
					AccessController.doPrivileged((PrivilegedAction<Object>) () -> {
						smartSingleton.afterSingletonsInstantiated();
						return null;
					}, getAccessControlContext());
				}
				else {
					smartSingleton.afterSingletonsInstantiated();
				}
				smartInitialize.end();
			}
		}
	}

什么是抽象BeanDefinition?

V1.1 getMergedLocalBeanDefinition

合并BeanDefinition

protected RootBeanDefinition getMergedLocalBeanDefinition(String beanName) throws BeansException {
		// 先从RootBeanDefinitionMap中获取当前beanName对应的RootBeanDefinition对象
		RootBeanDefinition mbd = this.mergedBeanDefinitions.get(beanName);
		//如果已经存在,则直接返回
		if (mbd != null && !mbd.stale) {
			return mbd;
		}
		//如果不存在,则继续向下判断
		return getMergedBeanDefinition(beanName, getBeanDefinition(beanName));
	}
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
	protected RootBeanDefinition getMergedBeanDefinition(
			String beanName, BeanDefinition bd, @Nullable BeanDefinition containingBd)
			throws BeanDefinitionStoreException {

		synchronized (this.mergedBeanDefinitions) {
			RootBeanDefinition mbd = null;
			RootBeanDefinition previous = null;

			// Check with full lock now in order to enforce the same merged instance.
			if (containingBd == null) {
				mbd = this.mergedBeanDefinitions.get(beanName);
			}

			if (mbd == null || mbd.stale) {
				previous = mbd;
				//如果当前BeanDefinition没有父类
				if (bd.getParentName() == null) {
					//判断bd是否是RootBeanDefinition的实例,如果是,则克隆一个新的RootBeanDifinition对象
					if (bd instanceof RootBeanDefinition) {
						mbd = ((RootBeanDefinition) bd).cloneBeanDefinition();
					}
					else {
						//直接创建一个RootBeanDefionition对象,并赋值
						mbd = new RootBeanDefinition(bd);
					}
				}
				else {
					//当bd存在父类的时候
					// pbd表示parentBeanDefinition
					BeanDefinition pbd;
					try {
						//获取父BeanDefinition的名称
						String parentBeanName = transformedBeanName(bd.getParentName());
						//如果 当前bean的名称与父类名称不相同,表示父类还存在父类,则需要继续递归调用
						//最终的效果是每一个父类都已经合并完了,当前beanDefinition在和父类进行合并
						if (!beanName.equals(parentBeanName)) {
							pbd = getMergedBeanDefinition(parentBeanName);
						}
						else {
							BeanFactory parent = getParentBeanFactory();
							if (parent instanceof ConfigurableBeanFactory) {
								pbd = ((ConfigurableBeanFactory) parent).getMergedBeanDefinition(parentBeanName);
							}
							else {
								throw new NoSuchBeanDefinitionException(parentBeanName,
										"Parent name '" + parentBeanName + "' is equal to bean name '" + beanName +
												"': cannot be resolved without a ConfigurableBeanFactory parent");
							}
						}
					}
					catch (NoSuchBeanDefinitionException ex) {
						throw new BeanDefinitionStoreException(bd.getResourceDescription(), beanName,
								"Could not resolve parent bean definition '" + bd.getParentName() + "'", ex);
					}

					// 子BeanDefinition的属性覆盖父BeanDefinition的属性,这就是合并
					//先用父类的BeanDefinition创建一个新的RootBeanDefinition
					mbd = new RootBeanDefinition(pbd);
					//在使用子类 的BeanDefinition覆盖RootBeanDefinition的属性
					mbd.overrideFrom(bd);
				}

				// 如果未设置bean的作用域,则默认设置未单例
				if (!StringUtils.hasLength(mbd.getScope())) {
					mbd.setScope(SCOPE_SINGLETON);
				}

				// A bean contained in a non-singleton bean cannot be a singleton itself.
				// Let's correct this on the fly here, since this might be the result of
				// parent-child merging for the outer bean, in which case the original inner bean
				// definition will not have inherited the merged outer bean's singleton status.
				if (containingBd != null && !containingBd.isSingleton() && mbd.isSingleton()) {
					mbd.setScope(containingBd.getScope());
				}

				
				if (containingBd == null && isCacheBeanMetadata()) {
					this.mergedBeanDefinitions.put(beanName, mbd);
				}
			}
			if (previous != null) {
				copyRelevantMergedBeanDefinitionCaches(previous, mbd);
			}
			return mbd;
		}

doGetBean

protected <T> T doGetBean(
			String name, @Nullable Class<T> requiredType, @Nullable Object[] args, boolean typeCheckOnly)
			throws BeansException {

		// name有可能是 &xxx 或者 xxx,如果name是&xxx,那么beanName就是xxx
		// name有可能传入进来的是别名,那么beanName就是id
		//具体看v1.1
		String beanName = transformedBeanName(name);
		Object beanInstance;

		// 优先从单例池中获取beanDefinition
		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 + "'");
				}
			}
			// 如果sharedInstance是FactoryBean,那么就调用getObject()返回对象
			beanInstance = getObjectForBeanInstance(sharedInstance, name, beanName, null);
		}

		else {
			// Fail if we're already creating this bean instance:
			// We're assumably within a circular reference.
			if (isPrototypeCurrentlyInCreation(beanName)) {
				throw new BeanCurrentlyInCreationException(beanName);
			}

			// Check if bean definition exists in this factory.
			BeanFactory parentBeanFactory = getParentBeanFactory();
			if (parentBeanFactory != null && !containsBeanDefinition(beanName)) {
				//如果beanDefinitionMap的keys中不包含beanName,则调用父类的bean工厂创建创建对象
				String nameToLookup = originalBeanName(name);
				if (parentBeanFactory instanceof AbstractBeanFactory) {
					//此处是递归处理,直至找到beanDefginition
					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) {
				markBeanAsCreated(beanName);
			}

			StartupStep beanCreation = this.applicationStartup.start("spring.beans.instantiate")
					.tag("beanName", name);
			try {
				if (requiredType != null) {
					beanCreation.tag("beanType", requiredType::toString);
				}
				//拿到beanName对应的RootBeanDefinition
				RootBeanDefinition mbd = getMergedLocalBeanDefinition(beanName);

				// 检查BeanDefinition是不是Abstract的
				checkMergedBeanDefinition(mbd, beanName, args);

				// 找出这个对象所依赖的所有bean的集合,该字段于构建rootBeandefinition的时候赋值
				String[] dependsOn = mbd.getDependsOn();
				if (dependsOn != null) {
					// dependsOn表示当前beanName所依赖的,当前Bean创建之前dependsOn所依赖的Bean必须已经创建好了
					for (String dep : dependsOn) {
						// beanName是不是被dep依赖了,如果是则出现了循环依赖
						//看代码v1.3
						if (isDependent(beanName, dep)) {
							throw new BeanCreationException(mbd.getResourceDescription(), beanName,
									"Circular depends-on relationship between '" + beanName + "' and '" + dep + "'");
						}
						// dep被beanName依赖了,存入dependentBeanMap中,dep为key,beanName为value
						registerDependentBean(dep, beanName);

						// 创建所依赖的bean
						try {
							getBean(dep);
						}
						catch (NoSuchBeanDefinitionException ex) {
							throw new BeanCreationException(mbd.getResourceDescription(), beanName,
									"'" + beanName + "' depends on missing bean '" + dep + "'", ex);
						}
					}
				}

				// bean是单例的情况
				if (mbd.isSingleton()) {
					//此处第二个参数lambda并不会马上执行,此处是相当于传入了一个对象,
					//该对象是getSingleton()方法中第二个参数接口的实例化,重写了该接口中唯一一个方法
					//具体看代码v1.2
					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;
						}
					});
					beanInstance = 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 {  // session.getAttriute(beaName)  setAttri
						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();
			}
		}

		// 检查通过name所获得到的beanInstance的类型是否是requiredType
        //看代码v1.5
		return adaptBeanInstance(name, beanInstance, requiredType);
	}

v1.1 transformedBeanName

根据传入的名字获取bean真正的名字(有可能传入的是别名或者工厂类别名,以&开头的),特别需要说明的是,spring针对于别名专门使用一个map(aliasMap)进行存储,key为别名,而value则是bean真正的名字。所以在创建bena第一步就需要先根据名字获取到bean真正的名字

protected String transformedBeanName(String name) {
		return canonicalName(BeanFactoryUtils.transformedBeanName(name));
	}
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
//先判断名字是否是工厂类的名字,如果不是,则直接返回名字,如果是以& 开头的,则循环截取第一个字符直到不以&开头
	public static String transformedBeanName(String name) {
		Assert.notNull(name, "'name' must not be null");
		if (!name.startsWith(BeanFactory.FACTORY_BEAN_PREFIX)) {
			return name;
		}
		return transformedBeanNameCache.computeIfAbsent(name, beanName -> {
			do {
				beanName = beanName.substring(BeanFactory.FACTORY_BEAN_PREFIX.length());
			}
			while (beanName.startsWith(BeanFactory.FACTORY_BEAN_PREFIX));
			return beanName;
		});
	}
↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
public String canonicalName(String name) {
		String canonicalName = name;
		// Handle aliasing...
		String resolvedName;
		do {
			//从别名map中获取bean的真实名字
			resolvedName = this.aliasMap.get(canonicalName);
			if (resolvedName != null) {
				canonicalName = resolvedName;
			}
		}
		while (resolvedName != null);
		return canonicalName;
	}
v1.2 getSingleton

获取单例对象

	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 + "'");
				}
				//创建bean之前的一些准备
				//1 判断beanName是否是被过滤的,如果是需要过滤的,则抛出异常
				//2 将beanName添加到singletonsCurrentlyInCreation集合中,表示bean正在创建
				//上面条件其中一个失败都会抛出异常
				beforeSingletonCreation(beanName);
				boolean newSingleton = false;
				boolean recordSuppressedExceptions = (this.suppressedExceptions == null);
				if (recordSuppressedExceptions) {
					this.suppressedExceptions = new LinkedHashSet<>();
				}
				try {
					//开始创建单例对象,调用外部的lambda表达式
					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;
					}
					//结束创建过程
					//1 判断beanName是否是被过滤的,如果是需要过滤的,则抛出异常
					//2 将beanName移除singletonsCurrentlyInCreation集合,表示bean不在创建过程中(已经创建结束了)
					//上面条件其中一个失败都会抛出异常
					afterSingletonCreation(beanName);
				}

				// 添加到单例池
				if (newSingleton) {
					addSingleton(beanName, singletonObject);
				}
			}
			return singletonObject;
		}
	}
v1.3 isDependent
	private boolean isDependent(String beanName, String dependentBeanName, @Nullable Set<String> alreadySeen) {
		if (alreadySeen != null && alreadySeen.contains(beanName)) {
			return false;
		}
		String canonicalName = canonicalName(beanName);
		//dependentBeanMapbeanName为key  以被key依赖的所有bean名字的集合为value
		Set<String> dependentBeans = this.dependentBeanMap.get(canonicalName);
		if (dependentBeans == null) {
			
			return false;
		}
		if (dependentBeans.contains(dependentBeanName)) {
			return true;
		}
		for (String transitiveDependency : dependentBeans) {
			if (alreadySeen == null) {
				alreadySeen = new HashSet<>();
			}
			alreadySeen.add(beanName);
			if (isDependent(transitiveDependency, dependentBeanName, alreadySeen)) {
				return true;
			}
		}
		return false;
	}
v1.4 adaptBeanInstance
	<T> T adaptBeanInstance(String name, Object bean, @Nullable Class<?> requiredType) {
		// Check if required type matches the type of the actual bean instance.
		if (requiredType != null && !requiredType.isInstance(bean)) {
			try {
				// SimpleTypeConverter
				Object convertedBean = getTypeConverter().convertIfNecessary(bean, requiredType);
				if (convertedBean == null) {
					throw new BeanNotOfRequiredTypeException(name, requiredType, bean.getClass());
				}
				return (T) convertedBean;
			}
			catch (TypeMismatchException ex) {
				if (logger.isTraceEnabled()) {
					logger.trace("Failed to convert bean '" + name + "' to required type '" +
							ClassUtils.getQualifiedName(requiredType) + "'", ex);
				}
				throw new BeanNotOfRequiredTypeException(name, requiredType, bean.getClass());
			}
		}
		return (T) bean;
	}

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

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

相关文章

圣诞节星星飘落的效果(微信小程序版)

圣诞节快到啦&#xff5e;&#x1f384;&#x1f384;&#x1f384;&#x1f384;咱们也试着做做小程序版本的星星✨飘落效果吧 在微信小程序内如何实现雪花飘落&#xff0c;星星飘落的效果呢&#xff5e; 先来个效果图&#xff1a; 1576672109245.gif 一步一步来&#xff1a;…

【稳定ACM出版、EI检索|武汉场线上线下结合】2024年第五届医学人工智能国际学术会议(ISAIMS 2024,8月13-17)

第五届医学人工智能国际学术会议&#xff08;ISAIMS2024&#xff09;将于2024年8月13-17日于荷兰阿姆斯特丹自由大学召开&#xff0c;国内分会场将于2024年10月25-27日于中国武汉召开。 本届会议将继续围绕人工智能在医学领域的最新研究成果&#xff0c;为来自国内外高等院校、…

智能化的Facebook未来:AI如何重塑社交网络的面貌?

随着人工智能&#xff08;AI&#xff09;技术的飞速发展&#xff0c;社交网络的面貌正在经历深刻的变革。Facebook&#xff08;现Meta Platforms&#xff09;作为全球最大的社交媒体平台之一&#xff0c;正积极探索如何利用AI技术来提升用户体验、优化内容管理并推动平台创新。…

全红婵夺冠后答记者问,太风趣了

8月6日晚&#xff0c;在巴黎结束的跳水女子10米台比赛中&#xff0c;17岁的中国选手全红婵以425.60分的高分成功卫冕&#xff0c;帮助中国代表团获得第22枚金牌。赛后采访时有记者想煽情&#xff0c;故意问到全红婵的哥哥来现场为她加油&#xff0c;结果小女子竟然毫无表情地回…

【python】Pandas处理Excel表格用法分析与最佳实践

✨✨ 欢迎大家来到景天科技苑✨✨ &#x1f388;&#x1f388; 养成好习惯&#xff0c;先赞后看哦~&#x1f388;&#x1f388; &#x1f3c6; 作者简介&#xff1a;景天科技苑 &#x1f3c6;《头衔》&#xff1a;大厂架构师&#xff0c;华为云开发者社区专家博主&#xff0c;…

AI大模型03:Function Calling

接口Interface &#xff08;1&#xff09;人际交互接口 UI &#xff08;User Interface&#xff09; &#xff08;2&#xff09;应用程序编程接口 API &#xff08;Application Programming Interface&#xff09; 接口能通的关键&#xff1a;是两方都要遵守约定。 &#xff0…

EI检索,2天录用,3天见刊!截稿在即,这本水刊你还不投吗?

点击关注&#xff1a;关注GZH【欧亚科睿学术】&#xff0c;GET完整版2023JCR分区列表&#xff01; &#x1f389; &#x1f389; &#x1f389; &#x1f389; 恭喜&#xff01;这本毕业水刊仅2天录用&#xff01;3天见刊&#xff01; 重要时间节点如下 2024-08-03 Sub…

360安全大模型为什么是“非卖品”?

大模型虽然不是万能的&#xff0c;但是没有大模型又是万万不能的。以AI大模型为动力引擎&#xff0c;AI正在重塑各行各业&#xff0c;并快速“飞入寻常百姓家”。 AI安全 以“模”制“模” 2024年全国两会&#xff0c;“人工智能”首次被写入政府工作报告。报告中提出&#xff…

Vue3 搭建前端工程,并使用idea配置项目启动

1 下载node.js 先下载 node.js LTS 并安装&#xff1a;node.js 的 npm&#xff0c;用于管理前端项目包依赖&#xff0c;这里以 14.17.3 这个版本为例。如果已经安装过 node.js&#xff0c;可以在设置中找到应用&#xff0c;点进去搜索 node.js 即可卸载 node.js 14.17.3 安装…

人生感悟|该如何最大化提升个人价值?

哈喽&#xff0c;你好啊&#xff0c;我是雷工&#xff01; 你肯定也听到过这个观点&#xff1a;人际关系的本质是价值交换&#xff0c;社会的本质就是价值互换。 我们立足社会&#xff0c;无论是上班还是创业&#xff0c;本质上都是在互换价值。 那么我们该如何最大化提升我…

Linux IPC-管道

前言 前面我们已经对进程概念、进程控制做了介绍&#xff01;本期开始将来介绍进程的最后一章进程间通信&#xff0c;即如何让两个进程进行通信&#xff01;本博客主要介绍管道&#xff01; 本期内容介绍 • 初识进程间通信 • 管道 一、初识进程间通信 1、进程间通信的概念…

基于Java+SpringBoot+Vue的教师工作量管理系统

基于JavaSpringBootVue的教师工作量管理系统 前言 ✌全网粉丝20W,csdn特邀作者、博客专家、CSDN[新星计划]导师、java领域优质创作者,博客之星、掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和毕业项目实战✌ &#x1f345;文末获取项目下载方式&#x1f345…

OpenAi not returning result and exited with code=0

题意&#xff1a;OpenAi 没有返回结果&#xff0c;程序以代码 0 退出 问题背景&#xff1a; Im trying to use OpenAI, but I cant get a result. Im accessing the API via Visual Studio Code. I have downloaded these extensions for Visual Studio Code: Code Runner and…

Bash考古以及 StackOverflow的2024年度技术统计报告

0.缘起 前段时间&#xff0c;有一次调试.sh时废了好大功夫&#xff0c;单独执行各行指令&#xff0c;可以&#xff0c;但是存储为.sh就不行了&#xff0c;最终发现&#xff0c;我漏加了文件头部的那个声明&#xff1a; #!/bin/bash https://wikimili.com/en/Stephen_R._Bourne…

代发考生战报:考试通过 H12-831科目

代发考生战报&#xff1a;考试通过 H12-831科目&#xff0c;同事2人分别2天考HCIP续认证&#xff0c;考试题基本都是题库里的&#xff0c;印象有1-2个题是新题&#xff0c;也许是自己没记准&#xff0c;题库更新很及时&#xff0c;题库看会了考试很简单&#xff0c;考试半个小时…

认识Modbus RTU与Modbus TCP

&#xff08;选自成都纵横智控-Modbus RTU与Modbus TCP协议区别详解 &#xff09; Modbus RTU 和 Modbus TCP 是两种常用的工业通信协议&#xff0c;用于连接电子设备&#xff0c;但它们在多方面有所不同。以下是它们的详细比较&#xff1a; Modbus RTU 协议类型&#xff1a; …

【精通Redis】Redis持久化和复制

文章目录 前言一、Redis持久化1.1 RDB快照手动触发自动触发save和bgsave的区别 1.2 AOF持久化appendonly配置 二、Redis复制2.1 开启Redis主从复制2.2 Redis复制的启动过程 前言 本文主要讨论Redis的持久化方式和复制特性。Redis的持久化方式有两种&#xff0c;一种叫RDB&…

越秀大悦城·天悦海湾 | 繁华底色 北方头等地标

每一座骄傲的城市&#xff0c;都以奔涌向前的气魄&#xff0c;屹立时代潮头。每一处让城市仰望的居所&#xff0c;亦怀揣与城市共美好的磐心&#xff0c;以焕新的生活方式致敬理想生活家。 越秀大悦城天悦海湾&#xff0c;踞青岛北站旁创新创业活力区&#xff0c;以优越生态基…

望获实时Linux与EtherCAT的硬实时解决方案

在追求极致实时性与可靠性的工业自动化领域&#xff0c;望获实时Linux以其卓越的实时性能和广泛的兼容性&#xff0c;正逐步成为工业控制领域的核心力量。结合EtherCAT这一高效通信协议&#xff0c;我们共同打造了一套创新的硬实时工业控制方案&#xff0c;旨在满足现代工业对快…