Spring源码分析篇一 @Autowired 是怎样完成注入的?究竟是byType还是byName亦两者皆有

news2025/7/19 0:53:18

1. 五种不同场景下 @Autowired 的使用

第一种情况 上下文中只有一个同类型的bean

配置类

package org.example.bean;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FruitConfiguration {

	@Bean("apple")
	public Fruit apple(){
		return new Fruit("apple");
	}
	

}

启动类

@ComponentScan(basePackages = "org.example.bean")
public class AutowiredTestDemo {

	@Autowired
	private Fruit fruit;

	public static void main(String[] args) {

		AnnotationConfigApplicationContext app = new AnnotationConfigApplicationContext(AutowiredTestDemo.class);
		AutowiredTestDemo autowiredTestDemo = app.getBean(AutowiredTestDemo.class);
		System.out.println(autowiredTestDemo.fruit);

	}


}

输出

Fruit{name='apple', price=null}

第二种情况 上下文中有两个同类型不同名的bean 且都与注入字段名称不一致

配置类

@Configuration
public class FruitConfiguration {

	@Bean("apple")
	public Fruit apple(){
		return new Fruit("apple");
	}

	@Bean("banana")
	public Fruit banana(){
		return new Fruit("banana");
	}

}

启动类

@ComponentScan(basePackages = "org.example.bean")
public class AutowiredTestDemo {

	@Autowired
	private Fruit fruit;

	public static void main(String[] args) {

		AnnotationConfigApplicationContext app = new AnnotationConfigApplicationContext(AutowiredTestDemo.class);
		AutowiredTestDemo autowiredTestDemo = app.getBean(AutowiredTestDemo.class);
		System.out.println(autowiredTestDemo.fruit);

	}

}

异常结果

No qualifying bean of type 'org.example.bean.Fruit' available: expected single matching bean but found 2: apple,banana

第三种情况 上下文中有两个同类型不同名的bean 且其中一个与注入字段名称一致

配置类

@Configuration
public class FruitConfiguration {

	@Bean("apple")
	public Fruit apple(){
		return new Fruit("apple");
	}

	@Bean("banana")
	public Fruit banana(){
		return new Fruit("banana");
	}

}

启动类

@ComponentScan(basePackages = "org.example.bean")
public class AutowiredTestDemo {

	@Autowired
	private Fruit apple;

	public static void main(String[] args) {

		AnnotationConfigApplicationContext app = new AnnotationConfigApplicationContext(AutowiredTestDemo.class);
		AutowiredTestDemo autowiredTestDemo = app.getBean(AutowiredTestDemo.class);
		System.out.println(autowiredTestDemo.apple);

	}


}

输出结果

Fruit{name='apple', price=null}

第四种情况 上下文中有两个同类型不同名的bean 且都与注入字段名称不一致但其中一个使用@Primary 注解

配置类

package org.example.bean;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

@Configuration
public class FruitConfiguration {

	@Bean("apple")
	public Fruit apple(){
		return new Fruit("apple");
	}

	@Primary
	@Bean("banana")
	public Fruit banana(){
		return new Fruit("banana");
	}

}

启动类

package org.example;

import org.example.bean.Fruit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;


@ComponentScan(basePackages = "org.example.bean")
public class AutowiredTestDemo {

	@Autowired
	private Fruit fruit;

	public static void main(String[] args) {

		AnnotationConfigApplicationContext app = new AnnotationConfigApplicationContext(AutowiredTestDemo.class);
		AutowiredTestDemo autowiredTestDemo = app.getBean(AutowiredTestDemo.class);
		System.out.println(autowiredTestDemo.fruit);

	}
}

输出结果

Fruit{name='banana', price=null}

第五种情况 上下文中有两个同类型不同名的bean 且都与注入字段名称不一致但注入时使用@Qualifier注解

配置类

package org.example.bean;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class FruitConfiguration {


	@Bean("apple")
	public Fruit apple(){
		return new Fruit("apple");
	}


	@Bean("banana")
	public Fruit banana(){
		return new Fruit("banana");
	}

}

启动类

package org.example;

import org.example.bean.Fruit;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.ComponentScan;


@ComponentScan(basePackages = "org.example.bean")
public class AutowiredTestDemo {

	@Autowired
	@Qualifier("apple")
	private Fruit fruit;

	public static void main(String[] args) {

		AnnotationConfigApplicationContext app = new AnnotationConfigApplicationContext(AutowiredTestDemo.class);
		AutowiredTestDemo autowiredTestDemo = app.getBean(AutowiredTestDemo.class);
		System.out.println(autowiredTestDemo.fruit);

	}


}

输出结果

Fruit{name='apple', price=null}

2.源码分析

启动类

public static void main(String[] args) {
		//创建应用上下文的同时注册AutowiredTestDemo
		AnnotationConfigApplicationContext app = new AnnotationConfigApplicationContext(AutowiredTestDemo.class);
		AutowiredTestDemo autowiredTestDemo = app.getBean(AutowiredTestDemo.class);
		System.out.println(autowiredTestDemo.fruit);
	}

org.springframework.context.annotation.AnnotationConfigApplicationContext#AnnotationConfigApplicationContext(java.lang.Class<?>…)

public AnnotationConfigApplicationContext(Class<?>... componentClasses) {
		//调用无参构造方法
		this();
		//注册组件
		//调用 BeanDefinitionReaderUtils.registerBeanDefinition 注册bd
		register(componentClasses);
		//刷新容器
		refresh();
	}

无参构造创建了一个AnnotatedBeanDefinitionReader对象与ClassPathBeanDefinitionScanner对象,用于读取和扫描带有注解的Bean定义信息

public AnnotationConfigApplicationContext() {
		this.reader = new AnnotatedBeanDefinitionReader(this);
		this.scanner = new ClassPathBeanDefinitionScanner(this);
	}

AnnotatedBeanDefinitionReader在初始化时将会往BeanFactory注册注解相关的处理器对象

org.springframework.context.annotation.AnnotatedBeanDefinitionReader#AnnotatedBeanDefinitionReader(org.springframework.beans.factory.support.BeanDefinitionRegistry, org.springframework.core.env.Environment)

public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry, Environment environment) {
		Assert.notNull(registry, "BeanDefinitionRegistry must not be null");
		Assert.notNull(environment, "Environment must not be null");
		this.registry = registry;
		this.conditionEvaluator = new ConditionEvaluator(registry, environment, null);
		AnnotationConfigUtils.registerAnnotationConfigProcessors(this.registry);
	}
if (!registry.containsBeanDefinition(CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME)) {
			RootBeanDefinition def = new RootBeanDefinition(ConfigurationClassPostProcessor.class);
			def.setSource(source);
			beanDefs.add(registerPostProcessor(registry, def, CONFIGURATION_ANNOTATION_PROCESSOR_BEAN_NAME));
		}

		if (!registry.containsBeanDefinition(AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME)) {
			RootBeanDefinition def = new RootBeanDefinition(AutowiredAnnotationBeanPostProcessor.class);
			def.setSource(source);
			beanDefs.add(registerPostProcessor(registry, def, AUTOWIRED_ANNOTATION_PROCESSOR_BEAN_NAME));
		}

		// Check for JSR-250 support, and if present add the CommonAnnotationBeanPostProcessor.
		if (jsr250Present && !registry.containsBeanDefinition(COMMON_ANNOTATION_PROCESSOR_BEAN_NAME)) {
			RootBeanDefinition def = new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class);
			def.setSource(source);
			beanDefs.add(registerPostProcessor(registry, def, COMMON_ANNOTATION_PROCESSOR_BEAN_NAME));
		}

		// Check for JPA support, and if present add the PersistenceAnnotationBeanPostProcessor.
		if (jpaPresent && !registry.containsBeanDefinition(PERSISTENCE_ANNOTATION_PROCESSOR_BEAN_NAME)) {
			RootBeanDefinition def = new RootBeanDefinition();
			try {
				def.setBeanClass(ClassUtils.forName(PERSISTENCE_ANNOTATION_PROCESSOR_CLASS_NAME,
						AnnotationConfigUtils.class.getClassLoader()));
			}
			catch (ClassNotFoundException ex) {
				throw new IllegalStateException(
						"Cannot load optional framework class: " + PERSISTENCE_ANNOTATION_PROCESSOR_CLASS_NAME, ex);
			}
			def.setSource(source);
			beanDefs.add(registerPostProcessor(registry, def, PERSISTENCE_ANNOTATION_PROCESSOR_BEAN_NAME));
		}

		if (!registry.containsBeanDefinition(EVENT_LISTENER_PROCESSOR_BEAN_NAME)) {
			RootBeanDefinition def = new RootBeanDefinition(EventListenerMethodProcessor.class);
			def.setSource(source);
			beanDefs.add(registerPostProcessor(registry, def, EVENT_LISTENER_PROCESSOR_BEAN_NAME));
		}

		if (!registry.containsBeanDefinition(EVENT_LISTENER_FACTORY_BEAN_NAME)) {
			RootBeanDefinition def = new RootBeanDefinition(DefaultEventListenerFactory.class);
			def.setSource(source);
			beanDefs.add(registerPostProcessor(registry, def, EVENT_LISTENER_FACTORY_BEAN_NAME));
		}

截屏2023-10-31 21.51.35

@Autowired注解是由 AutowiredAnnotationBeanPostProcessor 进行处理,而后者又实现了 InstantiationAwareBeanPostProcessorAdapter 与 MergedBeanDefinitionPostProcessor 两个扩展点接口

重写 MergedBeanDefinitionPostProcessor.postProcessMergedBeanDefinition,在bean实例化前,合并定义信息后执行。将需要注入的字段和方法与之需要注入的bean建立映射关系并封装成InjectedElement集合,再与class对象建立映射关系封装为InjectionMetadata对象并存入缓冲中

@Override
	public void postProcessMergedBeanDefinition(RootBeanDefinition beanDefinition, Class<?> beanType, String beanName) {
		//遍历类中的字段与方法,如果需要依赖注入,将封装成InjectionMetadata并放入缓冲中
		InjectionMetadata metadata = findAutowiringMetadata(beanName, beanType, null);
		//将成员添加到 beanDefinition 中,以便在配置过程中由外部管理器处理该成员的生命周期和依赖注入
		metadata.checkConfigMembers(beanDefinition);
	}

重写 InstantiationAwareBeanPostProcessorAdapter.postProcessProperties,此方法将在bean实例化后,属性填充前执行,此时当前bean已经完成了实例化,因此可以通过之前缓冲起来的映射关系,一一找出需要注入的字段和方法以及其对应需要注入的值,通过反射进行赋值操作

	public PropertyValues postProcessProperties(PropertyValues pvs, Object bean, String beanName) {
		//从缓存中获取当前bean字节码对象的注解元信息
		InjectionMetadata metadata = findAutowiringMetadata(beanName, bean.getClass(), pvs);
		try {
			//进行属性注入
			metadata.inject(bean, beanName, pvs);
		}
		catch (BeanCreationException ex) {
			throw ex;
		}
		catch (Throwable ex) {
			throw new BeanCreationException(beanName, "Injection of autowired dependencies failed", ex);
		}
		return pvs;
	}

大概了解了@Autowired的核心处理类AutowiredAnnotationBeanPostProcessor后,我们进一步分析上述五种情况,再源码底层是怎么处理的

情况一 有且仅有一个候选bean

org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.AutowiredFieldElement#inject

Field field = (Field) this.member;
			Object value;
			//默认false
			if (this.cached) {
				try {
					value = resolvedCachedArgument(beanName, this.cachedFieldValue);
				}
				catch (NoSuchBeanDefinitionException ex) {
					// Unexpected removal of target bean for cached argument -> re-resolve
					value = resolveFieldValue(field, bean, beanName);
				}
			}
			else {
				//处理当前bean所属字段的依赖注入,获取需要注入的对象
				value = resolveFieldValue(field, bean, beanName);
			}
			if (value != null) {
				//暴力访问
				ReflectionUtils.makeAccessible(field);
				//通过反射给当前需要注入的字段设置值
				field.set(bean, value);
			}

跟进resolveFieldValue(field, bean, beanName)方法一路往下直到doResolveDependency方法

org.springframework.beans.factory.support.DefaultListableBeanFactory#doResolveDependency

resolveMultipleBeans 方法是处理集合类型的依赖注入,而我们当前是非集合类型,因此会调用

findAutowireCandidates 处理依赖注入

			//集合类型注入
			Object multipleBeans = resolveMultipleBeans(descriptor, beanName, autowiredBeanNames, typeConverter);
			if (multipleBeans != null) {
				return multipleBeans;
			}
			//非集合类型注入
			Map<String, Object> matchingBeans = findAutowireCandidates(beanName, type, descriptor);
			if (matchingBeans.isEmpty()) {
				if (isRequired(descriptor)) {
					raiseNoMatchingBeanFound(type, descriptor.getResolvableType(), descriptor);
				}
				return null;
			}
protected Map<String, Object> findAutowireCandidates(
			@Nullable String beanName, Class<?> requiredType, DependencyDescriptor descriptor) {
		//根据需要注入的bean的类型 递归调用 beanNamesForTypeIncludingAncestors 获取父子BeanFactory中 类型的bean的名称
		// 注入 此处可能返回多个 候选的beanName
		String[] candidateNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(
				this, requiredType, true, descriptor.isEager());
		Map<String, Object> result = new LinkedHashMap<>(candidateNames.length);
		// 判断需要的类型是否是内建bean
		for (Map.Entry<Class<?>, Object> classObjectEntry : this.resolvableDependencies.entrySet()) {
			Class<?> autowiringType = classObjectEntry.getKey();
			if (autowiringType.isAssignableFrom(requiredType)) {
				Object autowiringValue = classObjectEntry.getValue();
				autowiringValue = AutowireUtils.resolveAutowiringValue(autowiringValue, requiredType);
				if (requiredType.isInstance(autowiringValue)) {
					result.put(ObjectUtils.identityToString(autowiringValue), autowiringValue);
					break;
				}
			}
		}
		// ,isSelfReference(beanName, candidate) 用于判断候选项是否是自身引用。
		// isAutowireCandidate(candidate, descriptor) 用于判断候选项是否符合自动装配的条件
		for (String candidate : candidateNames) {
			//调用DefaultListableBeanFactory.isAutowireCandidate() 完成@Qualifier注解过滤
			// 如果不满足将不会添加到候选Map中
			if (!isSelfReference(beanName, candidate) && isAutowireCandidate(candidate, descriptor)) {
				addCandidateEntry(result, candidate, descriptor, requiredType);
			}
		}
		if (result.isEmpty()) {
			boolean multiple = indicatesMultipleBeans(requiredType);
			// Consider fallback matches if the first pass failed to find anything...
			DependencyDescriptor fallbackDescriptor = descriptor.forFallbackMatch();
			for (String candidate : candidateNames) {
				if (!isSelfReference(beanName, candidate) && isAutowireCandidate(candidate, fallbackDescriptor) &&
						(!multiple || getAutowireCandidateResolver().hasQualifier(descriptor))) {
					addCandidateEntry(result, candidate, descriptor, requiredType);
				}
			}
			if (result.isEmpty() && !multiple) {
				// Consider self references as a final pass...
				// but in the case of a dependency collection, not the very same bean itself.
				for (String candidate : candidateNames) {
					if (isSelfReference(beanName, candidate) &&
							(!(descriptor instanceof MultiElementDescriptor) || !beanName.equals(candidate)) &&
							isAutowireCandidate(candidate, fallbackDescriptor)) {
						addCandidateEntry(result, candidate, descriptor, requiredType);
					}
				}
			}
		}
		return result;
	}

此时容器中只有一个Fruit类型的bean,回到doResolveDependency方法中,最终调用descriptor.resolveCandidate获取到bean实例,然后通过反射完成依赖注入

				//匹配到一个beanName 不满足
				if (matchingBeans.isEmpty()) {
				if (isRequired(descriptor)) {
					raiseNoMatchingBeanFound(type, descriptor.getResolvableType(), descriptor);
				}
				return null;
			}

			String autowiredBeanName;
			Object instanceCandidate;

			//只匹配到一个beanName 不满足
			if (matchingBeans.size() > 1) {
				autowiredBeanName = determineAutowireCandidate(matchingBeans, descriptor);
				if (autowiredBeanName == null) {
					if (isRequired(descriptor) || !indicatesMultipleBeans(type)) {
						return descriptor.resolveNotUnique(descriptor.getResolvableType(), matchingBeans);
					}
					else {
						// In case of an optional Collection/Map, silently ignore a non-unique case:
						// possibly it was meant to be an empty collection of multiple regular beans
						// (before 4.3 in particular when we didn't even look for collection beans).
						return null;
					}
				}
				instanceCandidate = matchingBeans.get(autowiredBeanName);
			}
				
				
				//调用 beanFactory.getBean(beanName)  根据名称获取需要注入的bean对象
				instanceCandidate = descriptor.resolveCandidate(autowiredBeanName, type, this);

因此,情况一 容器中只有一个目标类型的bean进行依赖注入就此结束

情况二,三,四 有两个同类型bean的两种情况

org.springframework.beans.factory.support.DefaultListableBeanFactory#doResolveDependency

如果根据类型匹配到两个beanName,将进入此判断语句中

			if (matchingBeans.size() > 1) {
				autowiredBeanName = determineAutowireCandidate(matchingBeans, descriptor);
				if (autowiredBeanName == null) {
					//是否必须注入
					if (isRequired(descriptor) || !indicatesMultipleBeans(type)) {
						return descriptor.resolveNotUnique(descriptor.getResolvableType(), matchingBeans);
					}
					else {
						// In case of an optional Collection/Map, silently ignore a non-unique case:
						// possibly it was meant to be an empty collection of multiple regular beans
						// (before 4.3 in particular when we didn't even look for collection beans).
						return null;
					}
				}
				instanceCandidate = matchingBeans.get(autowiredBeanName);
			}

由determineAutowireCandidate方法决定最终注入的beanName,如果无法选择出最合适的,将执行resolveNotUnique方法抛出NoUniqueBeanDefinitionException 异常,也就是我们情况二看到的异常

进入determineAutowireCandidate 方法

Class<?> requiredType = descriptor.getDependencyType();
		//@Primary 注解处理  是否有标记了@Primary注解
		String primaryCandidate = determinePrimaryCandidate(candidates, requiredType);
		if (primaryCandidate != null) {
			return primaryCandidate;
		}
		//javax.annotation.Priority 优先级匹配 值越小 优先级越高
		String priorityCandidate = determineHighestPriorityCandidate(candidates, requiredType);
		if (priorityCandidate != null) {
			return priorityCandidate;
		}
		// Fallback
		for (Map.Entry<String, Object> entry : candidates.entrySet()) {
			String candidateName = entry.getKey();
			Object beanInstance = entry.getValue();
			if ((beanInstance != null && this.resolvableDependencies.containsValue(beanInstance)) ||
					//将候选的beanName与依赖注入的字段名称进行匹配
					matchesBeanName(candidateName, descriptor.getDependencyName())) {
				return candidateName;
			}
		}
		return null;

首先针对第四种情况,如果有标记了@Primary注解的bean,将优先采用,如果都没有 ,则根据javax.annotation.Priority 注解的值选最小,值越小优先级越高。如果没有使用@Priority注解,将采用兜底方法

matchesBeanName(),哪一个候选的beanName与需要依赖注入的字段名称一致就使用谁

protected boolean matchesBeanName(String beanName, @Nullable String candidateName) {
		return (candidateName != null &&
				(candidateName.equals(beanName) || ObjectUtils.containsElement(getAliases(beanName), candidateName)));
	}

此时就是情况三 候选的beanName的名称与需要依赖注入的字段名称一致,依然能完成注入。

情况五 注入时使用@Qualifier注解

回到

org.springframework.beans.factory.support.DefaultListableBeanFactory#findAutowireCandidates

在获取到多个候选的beanName后,将会遍历集合,调用isSelfReference,isAutowireCandidate进行筛选,

而Qualifier注解的处理就在isAutowireCandidate方法中

for (String candidate : candidateNames) {
			//调用DefaultListableBeanFactory.isAutowireCandidate() 完成@Qualifier注解过滤
			// 如果不满足将不会添加到候选Map中
			if (!isSelfReference(beanName, candidate) && isAutowireCandidate(candidate, descriptor)) {
				addCandidateEntry(result, candidate, descriptor, requiredType);
			}
		}

跟进来到

org.springframework.beans.factory.annotation.QualifierAnnotationAutowireCandidateResolver#isAutowireCandidate

public boolean isAutowireCandidate(BeanDefinitionHolder bdHolder, DependencyDescriptor descriptor) {
		boolean match = super.isAutowireCandidate(bdHolder, descriptor);
		if (match) {
			//Qualifier 注解匹配 获取对象标准的Qualifier注解的值与候选的beanName进行匹配
			//有Qualifier注解才进行比较判断
			//否则直接返回true
			match = checkQualifiers(bdHolder, descriptor.getAnnotations());
			if (match) {
				MethodParameter methodParam = descriptor.getMethodParameter();
				if (methodParam != null) {
					Method method = methodParam.getMethod();
					if (method == null || void.class == method.getReturnType()) {
						match = checkQualifiers(bdHolder, methodParam.getMethodAnnotations());
					}
				}
			}
		}
		return match;
	}
{
		if (ObjectUtils.isEmpty(annotationsToSearch)) {
			return true;
		}
		SimpleTypeConverter typeConverter = new SimpleTypeConverter();
		for (Annotation annotation : annotationsToSearch) {
			Class<? extends Annotation> type = annotation.annotationType();
			boolean checkMeta = true;
			boolean fallbackToMeta = false;
			//有Qualifier注解才进行比较判断
			if (isQualifier(type)) {
				if (!checkQualifier(bdHolder, annotation, typeConverter)) {
					fallbackToMeta = true;
				}
				else {
					checkMeta = false;
				}
			}
			if (checkMeta) {
				boolean foundMeta = false;
				for (Annotation metaAnn : type.getAnnotations()) {
					Class<? extends Annotation> metaType = metaAnn.annotationType();
					if (isQualifier(metaType)) {
						foundMeta = true;
						// Only accept fallback match if @Qualifier annotation has a value...
						// Otherwise it is just a marker for a custom qualifier annotation.
						if ((fallbackToMeta && StringUtils.isEmpty(AnnotationUtils.getValue(metaAnn))) ||
								!checkQualifier(bdHolder, metaAnn, typeConverter)) {
							return false;
						}
					}
				}
				if (fallbackToMeta && !foundMeta) {
					return false;
				}
			}
		}
		return true;
	}

至此,Spring针对 @Autowired 注解在五种不同的情况下进行依赖注入我们已经分析完毕

3. 结论

@Autowired 首先会通过 BeanFactoryUtils.beanNamesForTypeIncludingAncestors (递归获取父子BeanFactory调用getBeanNamesForType方法),根据需要进行依赖注入的字段的类型或者方法参数的类型取获取相应的beanName,如果注入的是非集合类型的对象,并且找到了一个以上的候选beanName,则下一步会去判断是否有标记优先级,如果都没有则会进行名称匹配,也就是将候选的beanName与字段名或参数名进行equals比较

byType -> 优先级比较 -> byName

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

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

相关文章

06、Caused by: java.nio.charset.MalformedInputException: Input length = 1

目录 问题&#xff1a;原因&#xff1a;解决方法&#xff1a; 问题&#xff1a; Caused by: java.nio.charset.MalformedInputException: Input length 1 原因&#xff1a; 应该是中文有哪些文字导致的。 yml 编码格式出错 解决方法&#xff1a; 直接这里把GBK改成 utf-8…

做抖音短视频会经历哪些阶段?

今天来聊聊那些在抖音做大的老板&#xff0c;从开始到后期经历的四个阶段&#xff0c;以及每个阶段的工作重心 1、0—1的阶段 0—1的起步阶段是整个阶段最有难度的一环&#xff0c;很多人对0到1的认知是有错误的&#xff0c;以为爆过几条视频就已经进阶了 想要实现0-1的突破…

使用 Docker 部署高可用 MongoDB 分片集群

使用 Docker 部署 MongoDB 集群 Mongodb 集群搭建 mongodb 集群搭建的方式有三种&#xff1a; 主从备份&#xff08;Master - Slave&#xff09;模式&#xff0c;或者叫主从复制模式。副本集&#xff08;Replica Set&#xff09;模式。分片&#xff08;Sharding&#xff09;…

装备制造行业云MES解决方案

一、装备制造行业发展现状&#xff1a; 机械制造业主要是通过对金属原材料物理形状的改变、加工组装进而成为产品。机械制造业生产的主要特点是&#xff1a;离散为主、流程为辅、装配为重点。 工业生产基本上分为两大方式&#xff1a; 1.离散型&#xff1a;离散型是指以一个…

智能问答进阶之路:RAG(大模型检索增强生成)框架详解与实战,融合检索与生成助力智能系统更上层楼

搜索推荐系统专栏简介:搜索推荐全流程讲解(召回粗排精排重排混排)、系统架构、常见问题、算法项目实战总结、技术细节以及项目实战(含码源) 专栏详细介绍:搜索推荐系统专栏简介:搜索推荐全流程讲解(召回粗排精排重排混排)、系统架构、常见问题、算法项目实战总结、技术…

市场洗牌,全新一代MiniLED背光技术大放异彩

MiniLED背光是一种采用微小尺寸LED灯珠作为背光源的技术。相比传统的LED背光&#xff0c;MiniLED采用更小的LED尺寸&#xff08;通常在100微米至200微米之间&#xff09;&#xff0c;使得显示屏幕的亮度和对比度得以大幅提升。MiniLED背光技术作为显示行业的新宠儿&#xff0c;…

外汇天眼:3大假投资诈骗手法公开,助你识破假券商及黑平台!

去年以来物价持续上涨&#xff0c;不少人的薪水涨幅却不如预期&#xff0c;导致资产实质缩水。 面对生活成本不断增加&#xff0c;愈来愈多人意识到投资的重要性&#xff0c;并且开始寻找各种获利的渠道与机会。 与此同时&#xff0c;诈骗集团也利用人们想赚钱的心理&#xff0…

家用小型洗衣机哪款性价比高?好用不贵内衣洗衣机测评

很多人在休息的时候&#xff0c;都会抽出一些时间来清洗自己的衣物&#xff0c;但是他们忽略了一个问题&#xff0c;内裤不能和平时穿的外套一起用洗衣机清洗&#xff0c;主要原因是一般的洗衣机不能把内衣清洗干净&#xff0c;而且如果和平时穿的外套一起洗的话&#xff0c;内…

【嵌入式项目应用】__用于搭建调试输出、建立时间系统的嵌入式框架“Zorb Framework”

目录 一、什么是Zorb&#xff1f; 二、嵌入式环境搭建 三、调试输出 四、实现断言 五、建立时间系统 六、结束语 (*&#xffe3;︶&#xffe3;)创作不易&#xff01;期待你们的 点赞、收藏和评论喔。 一、什么是Zorb&#xff1f; Zorb Framework是一个基于面向对象的思…

visinextek的sdk编译

编译sdk 1、修改编译链路径 cd customer-rel/board/package/mk/ vi common.mksudo echo ‘PATH“/home/johan/share/vs839/vs-linux/x86-arm/gcc-linaro-7.5.0-aarch64-linux-gnu/bin:$PATH”’ >> /etc/profile source /etc/profile 2、bypass DSP 编译&#xff0c;…

Leetcode循环队列

这道题十分考验我们对队列的理解。 文章目录 队列的介绍队列的实现进入正题 队列的介绍 队列是一种只允许在一段进行插入&#xff0c;在另一端进行删除的数据操作的特殊线性结构&#xff0c;&#xff0c;因此决定了他具有先入先出的特点&#xff0c;其中进行插入操作的一段叫做…

MFC打开控制台的常用方式

工程项目中&#xff0c;想打开控制台的&#xff0c;简单打印日志 &#xff08;1&#xff09;依次打开&#xff1a; 项目配置属性——>生成事件——>后期生成事件&#xff1a;命令行 &#xff08;2&#xff09;输入&#xff1a; editbin /SUBSYSTEM:CONSOLE $(OUTDIR)\$…

pppoe拨号案例

R3服务端 interface LoopBack0 ip address 1.1.1.1 255.255.255.255 aaa local-user test password cipher admin local-user test service-type ppp ip pool test network 100.0.0.0 mask 255.255.255.0 interface Virtual-Template0 ppp authentication-mode chap remote …

【设计模式】第23节:行为型模式之“策略模式”

一、简介 策略模式&#xff1a;定义一族算法类&#xff0c;将每个算法分别封装起来&#xff0c;让它们可以互相替换。策略模式可以使算法的变化独立于使用它们的客户端&#xff08;这里的客户端代指使用算法的代码&#xff09;。 二、适用场景 动态选择算法多种类似的行为 …

CondConv 动态卷积学习笔记 (附代码)

论文地址:https://arxiv.org/abs/1904.04971 代码地址&#xff1a;https://github.com/tensorflow/tpu/tree/master/models/official/efficientnet/condconv 1.是什么&#xff1f; CondConv是一种条件参数卷积&#xff0c;也称为动态卷积&#xff0c;它是一种即插即用的模块&…

数据结构之集合框架

1.Java集合框架的定义 Java 集合框架 Java Collection Framework &#xff0c;又被称为容器 container &#xff0c;是定义在 java.util 包下的一组接口 interfaces和其实现类 classes 。 其主要表现为将多个元素 element 置于一个单元中&#xff0c;用于对这些元素进行…

向上管理中的沟通技巧

一. 背景 我们要弄清楚两个问题为什么要向上管理呢&#xff0c;向上管理主要是要做什么呢&#xff1f; 首先&#xff0c;第一个问题为什么要向上管理&#xff1f;向上管理的本质是为了同时给公司、上司和自己带来最好的结果&#xff0c;并有意识地配合和改变工作方法&#xf…

iPhone连不上Wi-Fi?看完这篇文章你就知道了!

大家在使用苹果手机的过程中有没有遇到过这样的情况&#xff1a;手机突然连接不上Wi-Fi&#xff0c;或者连接了也根本使用不了。遇到上述情况请不要着急&#xff0c;iphone连不上wifi是由很多种原因导致的。那么&#xff0c;iPhone连接不上Wi-Fi时该怎么办呢&#xff1f; 我们…

测试可用的安防视频分析软件:烟火检测、车型检测、玩手机打电话检测、厨帽检测、抽烟检测、人员入侵检测

下载地址&#xff1a;https://pan.baidu.com/s/1R1MvD_KQ3uB-0KL_N3is-w?pwdwa33 随着AI、大数据、云计算和边缘计算等技术的迅猛发展&#xff0c;我国的视频监控市场正处于全新的阶段。借助AI深度学习技术的进步&#xff0c;现代化的安防视频监控系统通过边缘计算设备上的AI识…

用友NC BeanShell RCE漏洞

一、漏洞简介 用友 NC 是面向集团企业的管理软件&#xff0c;其在同类市场占有率中达到亚太第一。用友 NC 由于对外开放了 BeanShell 接口&#xff0c;攻击者可以在未授权的情况下直接访问该接口&#xff0c;并构造恶意数据执行任意代码从而获取服务器权限。 二、影响版本 NC …