解读Spring-context的property-placeholder

        在spring中,如果要给程序定义一些参数,可以放在application.properties中,通过<context:property-placeholder>加载这个属性文件,然后就可以通过@value给我们的变量自动赋值,如果你们的程序可能运行在多个环境中(比如开发、测试和生产)你也可以定义多套属性文件。这些用法我们早已司空见惯,今天我们就来理一下来龙去脉。

context:property-placeholder

用法

<context:property-placeholder>的主要属性:

属性名        说明
location文件位置,多个之间通过如逗号/分号等分隔;
file-encoding文件编码
ignore-resource-not-found如果属性文件找不到,是否忽略,默认false,即不忽略,找不到将抛出异常 
ignore-unresolvable是否忽略解析不到的属性,如果不忽略,找不到将抛出异常
properties-ref本地java.util.Properties配置
local-override是否本地覆盖模式,即如果true,本地属性文件的优先级高于环境变量
system-properties-mode

系统属性模式

ENVIRONMENT(默认),

FALLBACK(环境变量兜底)

NEVER(不使用环境变量)

OVERRIDE(环境变量覆盖)                            

历史渊源

要说清楚这个标签,涉及spring3.1这个重要版本,从这个版本起,spring抽象了Environment接口,这个标签的处理器也从PropertyPlaceholderConfigurer被过渡到PropertySourcesPlaceholderConfigurer(下面细讲)。

关于system-properties-mode属性

在3.1之前,只有三个取值,当时的处理器还是PropertyPlaceholderConfigurer,这个处理现在已经不推荐使用,这个变量的作用是:声明对系统属性和环境变量的使用方式。

属性值说明
NEVER不使用系统属性和环境变量
OVERRIDE

使用系统属性和环境变量覆盖属性文件

即系统属性和环境变量优先

FALLBACK

使用系统属性和环境变量来做兜底

即属性文件优先

在3.1之后,多了一个新的取值Environment,spring从这个版本起引入了Environment接口,如果system-properties-mode属性被配置为Environment,则使用采用PropertySourcesPlaceholderConfigurer进行占位符处理,这也是3.1之后的默认处理方式。

见PropertyPlaceholderBeanDefinitionParser:

    @Override
	protected Class<?> getBeanClass(Element element) {
        //system-properties-mode设置为ENVIRONMENT,则走PropertySourcesPlaceholderConfigurer
		if (SYSTEM_PROPERTIES_MODE_DEFAULT.equals(element.getAttribute(SYSTEM_PROPERTIES_MODE_ATTRIBUTE))) {
			return PropertySourcesPlaceholderConfigurer.class;
		}
        //否则走PropertyPlaceholderConfigurer(兼容处理)
		return PropertyPlaceholderConfigurer.class;
	}

各种配置的优化级

由于system-properties-mode只推荐使用ENVIRONMENT,其它三种方式只是保持对老版本spring的兼容,这里主要分析在ENVIRONMENT模式下,属性文件,properties-ref,系统属性,环境变量的优先级

local-override属性值优先级
false

System.getProperty()>System.getenv()>

location属性文件>properties-ref

trueproperties-ref>location属性文件>System.getProperty()>System.getenv()

默认情况下,系统属性和环境变量一起构成StandardEnvironment,系统属性优先于环境变量。

public class StandardEnvironment extends AbstractEnvironment {

	/** System environment property source name: {@value}. */
	public static final String SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME = "systemEnvironment";

	/** JVM system properties property source name: {@value}. */
	public static final String SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME = "systemProperties";


    //加入(定义)两个PropertySource:这个是系统属性,一个是环境变量
	@Override
	protected void customizePropertySources(MutablePropertySources propertySources) {
		propertySources.addLast(
				new PropertiesPropertySource(SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME, getSystemProperties()));
		propertySources.addLast(
				new SystemEnvironmentPropertySource(SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME, getSystemEnvironment()));
	}

}

PropertySourcesPlaceholderConfigurer

PropertySourcesPlaceholderConfigurer维护一个MutablePropertySources,该对象放着两个PropertySource,一个对Environment做了一个包装,一个是合并本地的属性文件配置。并local-override的配置的不同,决定这两个PropertySource的优先级:

#postProcessBeanFatcory

作为一个BeanFactoryPostProcessor,该方法会在Bean实例化之前被spring容器调用

public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
		if (this.propertySources == null) {
			this.propertySources = new MutablePropertySources();
			if (this.environment != null) {
				this.propertySources.addLast(
						//将Environment封装成一个新的PropertySource,后面的占位符处理将委托给Environment对象
					new PropertySource<Environment>(ENVIRONMENT_PROPERTIES_PROPERTY_SOURCE_NAME, this.environment) {
						@Override
						@Nullable
						public String getProperty(String key) {
							return this.source.getProperty(key);
						}
					}
				);
			}
			try {
				//合并properties-ref和location的属性合并,并统称为localProperties
				PropertySource<?> localPropertySource =
						new PropertiesPropertySource(LOCAL_PROPERTIES_PROPERTY_SOURCE_NAME, mergeProperties());
				if (this.localOverride) {
					//如果本地覆盖,则将本地属性放在首位(优先)
					this.propertySources.addFirst(localPropertySource);
				}
				else {//否则将本地属性放在未位
					this.propertySources.addLast(localPropertySource);
				}
			}
			catch (IOException ex) {
				throw new BeanInitializationException("Could not load properties", ex);
			}
		}
		//处理属性占位符,这里只是将占位符处理器注入给到BeanFactory
		processProperties(beanFactory, new PropertySourcesPropertyResolver(this.propertySources));
		this.appliedPropertySources = this.propertySources;
	}

#mergeProperties

mergeProperties方法:合并location指向的属性文件和properties-ref指向的配置对象。如果全地覆盖,则使用properties-ref覆盖location的配置,否则相反。其中loadProperties是加载location指定的属性文件,并解析代析Properties对象,代码略

protected Properties mergeProperties() throws IOException {
		Properties result = new Properties();

		if (this.localOverride) {
			// 如果本地覆盖,则先加载location指定的属性文件
			loadProperties(result);
		}

		if (this.localProperties != null) {
            //如果定义了properties-ref属性,则进行属性合并
			for (Properties localProp : this.localProperties) {
				CollectionUtils.mergePropertiesIntoMap(localProp, result);
			}
		}

		if (!this.localOverride) {
			//如果非本地覆盖,则最后加载location指定的属性文件
			loadProperties(result);
		}

		return result;
	}

#processProperties

进入processProperties方法:ConfigurablePropertyResolver 最终被转换成StringValueResolver,然后调用doProcessProperties。

protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
			final ConfigurablePropertyResolver propertyResolver) throws BeansException {

		propertyResolver.setPlaceholderPrefix(this.placeholderPrefix);
		propertyResolver.setPlaceholderSuffix(this.placeholderSuffix);
		propertyResolver.setValueSeparator(this.valueSeparator);

		StringValueResolver valueResolver = strVal -> {
			String resolved = (this.ignoreUnresolvablePlaceholders ?
					propertyResolver.resolvePlaceholders(strVal) :
					propertyResolver.resolveRequiredPlaceholders(strVal));
			if (this.trimValues) {
				resolved = resolved.trim();
			}
			return (resolved.equals(this.nullValue) ? null : resolved);
		};

		doProcessProperties(beanFactoryToProcess, valueResolver);
	}

#doProcessProperties

进入doProcessProperties,该方法进行处理BeanDefinition中的各种占位符,最后把StringValueResolver注入给beanFactory,供属性代替使用,后面会讲到。

protected void doProcessProperties(ConfigurableListableBeanFactory beanFactoryToProcess,
			StringValueResolver valueResolver) {

		BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver);

		String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
		for (String curName : beanNames) {
			if (!(curName.equals(this.beanName) && beanFactoryToProcess.equals(this.beanFactory))) {
				BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(curName);
				try {
                    //处理BeanDefinition中的各种占位符(注意:不是bean本身)
					visitor.visitBeanDefinition(bd);
				}
				catch (Exception ex) {
					throw new BeanDefinitionStoreException(bd.getResourceDescription(), curName, ex.getMessage(), ex);
				}
			}
		}

		beanFactoryToProcess.resolveAliases(valueResolver);
        //在这里把StringValueResolver注入给beanFactory,供属性代替使用
		beanFactoryToProcess.addEmbeddedValueResolver(valueResolver);
	}

相关接口说明

PropertyResolver接口

在PropertySourcesPlaceholderConfigurer中会创建PropertyResolver接口对象,该对象持有配置属性源的引用,并提供获取属性值,处理占位符等功能。详见:PropertySourcesPropertyResolver这里只列出接口的定义:

public interface PropertyResolver {
	boolean containsProperty(String key);

	@Nullable
	String getProperty(String key);//获取属性值
	String getProperty(String key, String defaultValue);
	@Nullable
	<T> T getProperty(String key, Class<T> targetType);
	<T> T getProperty(String key, Class<T> targetType, T defaultValue);

	String getRequiredProperty(String key) throws IllegalStateException;
	<T> T getRequiredProperty(String key, Class<T> targetType) throws IllegalStateException;

	String resolvePlaceholders(String text);//处理占位符
	String resolveRequiredPlaceholders(String text) throws IllegalArgumentException;
}

Environment

Environment接口是Spring体系里一个既熟悉又陌生的接口。

Spring 3.1 开始引入 Environment 抽象,它统一 Spring 配置属性的存储、占位符处理和类型转换,支持更丰富的配置属性源(PropertySource)。

条件化 Spring Bean 装配管理:
通过 Environment Profiles 信息,帮助 Spring 容器提供条件化地装配 Bean。

@Profile

在spring应用中,通常会通过变量spring.profiles.active去指定当前环境,而注解@Profile可以加上Bean上,让Bean在某个环境中生效,其实现通过@Conditional(ProfileCondition.class),这里不展开。

Environment接口继承自PropertyResolver,同时扩展了对profile的操作,通过profile来标识当前处于哪个环境(开发、测试或生产)

public interface Environment extends PropertyResolver {
    //获取当前profile(环境)
	String[] getActiveProfiles();
	String[] getDefaultProfiles();

	@Deprecated
	boolean acceptsProfiles(String... profiles);

    //判断当前环境是否与给定profiles一致
	boolean acceptsProfiles(Profiles profiles);
}

AbstractEnvironment

结合抽象类AbstractEnvironment,可以更好地理解Environment的行为

public abstract class AbstractEnvironment implements ConfigurableEnvironment {

	//维护当前活动的profile环境
    private final Set<String> activeProfiles = new LinkedHashSet<>();

	private final Set<String> defaultProfiles = new LinkedHashSet<>(getReservedDefaultProfiles());
    //维护各种配置属性源
	private final MutablePropertySources propertySources = new MutablePropertySources();
    //持有占位符处理器
	private final ConfigurablePropertyResolver propertyResolver =
			new PropertySourcesPropertyResolver(this.propertySources);
}

        AbstractEnvironment由于知道当前是哪个环境,就知道需要装载哪些配置文件,而MutablePropertySources是可变的PropertySources,它允许用户动态地添加各种PropertySource,比如来自配置中心的配置。最后由propertyResolver完成最后的占位符处理操作。

PropertySource

属性源就是对一类配置(可以是属性配置文件,系统属性,环境变量等)的封装,同时给这个配置一个名称

public abstract class PropertySource<T> {

	protected final String name;//名称

	protected final T source;//配置,存放键值对

    ...

}

MapPropertySource:一种基于Map实现的简单的PropertySource。

public class MapPropertySource extends EnumerablePropertySource<Map<String, Object>> {

	public MapPropertySource(String name, Map<String, Object> source) {
		super(name, source);
	}


	@Override
	@Nullable
	public Object getProperty(String name) {
		return this.source.get(name);
	}

	@Override
	public boolean containsProperty(String name) {
		return this.source.containsKey(name);
	}

	@Override
	public String[] getPropertyNames() {
		return StringUtils.toStringArray(this.source.keySet());
	}

}

只要你喜欢,你可以把Map当做你的配置源,也就是说你可以把创建一个Map作为应用程序的配置。一些主要的PropertySource.

PropertySource 类型说明
org.springframework.core.env.CommandLinePropertySource命令行配置属性源
org.springframework.jndi.JndiPropertySourceJDNI 配置属性源
org.springframework.core.env.MapPropertySource基于Map对象的配置属性源
org.springframework.core.env.PropertiesPropertySource

扩展自MapPropertySource,

Properties 配置属性源

org.springframework.web.context.support.ServletConfigPropertySourceServlet 配置属性源
org.springframework.web.context.support.ServletContextPropertySourceServletContext 配置属性源
org.springframework.core.env.SystemEnvironmentPropertySource环境变量配置属性源

其中PropertiesPropertySource扩展自MapPropertySource,我们的系统属性,以及我们属性配置文件,最终会被封装成PropertiesPropertySource,其它配置属性源请自行脑补。

PropertySources

PropertySources是PropertySource的集合,是一个继承自Iterable的接口,提供了一些方便操作属性源的方法:

  • addFirst():将属性源放在首位,即优先级最高
  • addLast():将属性源放在未位,即优先级最低

MutablePropertySources

PropertySources有一个唯一的实现:MutablePropertySources。该实现就是Environment对象里的可变属性源,基于该对象,可以实现PropertySource的动态地添加,并按需对属性源进行优先级排序。

注:在spring中有对应的注解,如@PropertySource和@PropertySources可以以注解的形成来配置属性源,随着applicationContext.xml慢慢被摈弃,正逐渐代替<context:property-placeholder>,这里不展开。

如何动态添加属性源

通过调用ConfigurableApplicationContext#getEnvironment可以获得到Environment引用,再把自己扩展的PropertySource添加到它的MutablePropertySources里面。

ConfigurableEnvironment environment = context.getEnvironment();
MapPropertySource mapPropertySource = new MapPropertySource("my-map-properties", new HashMap<>());
MutablePropertySources propertySources = environment.getPropertySources();
propertySources.addFirst(mapPropertySource);

@Value的实现

上面讲了Enviroment抽象以及属性源优先级,下面讲@Value注释如何实现属性值的替换。

AutowiredAnnotationBeanPostProcessor

多数人对@Value这一块并不陌生,主要的实现就是AutowiredAnnotationBeanPostProcessor,该BeanPostProcessor主要处理@Value和@Autowired注解。这里就不贴代码了,大概流程如下:

        spring容器在创建完Bean对象实现实例之后,进入属性注入阶段会回postProcessPropertyValues方法(BeanPostProcessor的回调机制),进而会调用beanFactory.resolveDependency(AutowiredAnnotationBeanPostProcessor实现了BeanFactoryAware接口,持有beanFactory对象引用)

DefaultListableBeanFactory#doResolveDependency

@Nullable
public Object doResolveDependency(DependencyDescriptor descriptor, @Nullable String beanName,
			@Nullable Set<String> autowiredBeanNames, @Nullable TypeConverter typeConverter) throws BeansException {

		InjectionPoint previousInjectionPoint = ConstructorResolver.setCurrentInjectionPoint(descriptor);
		try {
			Object shortcut = descriptor.resolveShortcut(this);
			if (shortcut != null) {
				return shortcut;
			}

			Class<?> type = descriptor.getDependencyType();
			Object value = getAutowireCandidateResolver().getSuggestedValue(descriptor);
			if (value != null) {
				if (value instanceof String) {
                    //这里处理属性值
					String strVal = resolveEmbeddedValue((String) value);
					BeanDefinition bd = (beanName != null && containsBean(beanName) ?
							getMergedBeanDefinition(beanName) : null);
					value = evaluateBeanDefinitionString(strVal, bd);
				}
                //对属性值做类型转换
				TypeConverter converter = (typeConverter != null ? typeConverter : getTypeConverter());
				try {
					return converter.convertIfNecessary(value, type, descriptor.getTypeDescriptor());
				}
				catch (UnsupportedOperationException ex) {
					// A custom TypeConverter which does not support TypeDescriptor resolution...
					return (descriptor.getField() != null ?
							converter.convertIfNecessary(value, type, descriptor.getField()) :
							converter.convertIfNecessary(value, type, descriptor.getMethodParameter()));
				}
			}
...
}

2)beanFactory.resolveDependency的主要作用是处理属性依赖,可以处理对象的注入也可以处理属性值的注入。如果是@Value属性值注入,则进行占位符处理,而在BeanFactory里,处理占位符的对象是StringValueResolver,BeanFactory维护多个StringValueResolver:

public String resolveEmbeddedValue(@Nullable String value) {
		if (value == null) {
			return null;
		}
		String result = value;
        //这里的StringValueResolver有一个是PropertySourcesPlaceholderConfigurer注入的
		for (StringValueResolver resolver : this.embeddedValueResolvers) {
			result = resolver.resolveStringValue(result);
			if (result == null) {
				return null;
			}
		}
		return result;
	}

BeanFactory对属性值的处理就是交给多个StringValueResolver去循环处理,这里的StringValueResolver有一个是PropertySourcesPlaceholderConfigurer注入的,可回头看PlaceholderConfigurerSupport#doProcessProperties。

StringValueResolver接口

回到StringValueResolver接口,该接口只做一件事,那就是做占位符处理(将一个字符串转成另一个字符串)

@FunctionalInterface
public interface StringValueResolver {

	@Nullable
	String resolveStringValue(String strVal);

}

那问题来了,为何BeanFactory不直接持有PropertyResolver对象,而要使用新的接口呢?

这里要说明的是PropertyResolver接口是spring3.1才引入的,而StringValueResolver则在spring2.5就已经存在,一方面BeanFactory原先持有的就是StringValueResolver,另一个方面这突显了接口设计的单一原则,因为对于BeanFactory而言,就仅仅是想得到目标的属性值。因而也就没有必要换成PropertyResolver接口。

总结

回顾<context:property-placeholder>和@Value的整个过程:

1)自spring3.1起,采用PropertySourcesPlaceholderConfigurer维护一个聚合了Environment(环境变量和系统属性)和本地属性文件的配置,将Environment包装成一个新的PropertySource中。

2)PropertySourcesPlaceholderConfigurer维护一个MutablePropertySources,该对象放着两个PropertySource,一个对Environment做了一个包装,一个是合并本地的属性文件配置。并local-override的配置的不同,决定这两个PropertySource的优先级

3)PropertySourcesPlaceholderConfigurer创建了PropertyResolver接口对象,并适配成StringValueResolver接口,传递给BeanFactory,由于PropertyResolver对象持有MutablePropertySources引用,因此这个MutablePropertySources对BeanFactory可见。

4)BeanFactory维护着一系列StringValueResolver对象,并提供处理对象依赖(包括属性值)的能力。

5)属性值注入阶段,AutowiredAnnotationBeanPostProcessor通过调用BeanFactory的doResolveDependency实现属性注入,内部调用StringValueResolver进行属性值处理,而本质上就是调用PropertySourcesPlaceholderConfigurer的PropertyResolver,最终使用的也是PropertySourcesPlaceholderConfigurer中的的MutablePropertySources。

6)得益于Environment的MutablePropertySources,应用可以更灵活地管理各种配置及其优先级。

最后献上一个类图:

by simple

 

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

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

相关文章

Qt 5. QSerialPort串口收发

1. 代码 //ex2.cpp #include "ex2.h" #include "ui_ex2.h" #include <QtSerialPort/QSerialPort> #include <QtSerialPort/QSerialPortInfo>int static cnt 0;Ex2::Ex2(QWidget *parent): QDialog(parent), ui(new Ui::Ex2) {ui->setupUi…

【Golang 接口自动化03】 解析接口返回XML

目录 解析接口返回数据 定义结构体 解析函数&#xff1a; 测试 优化 资料获取方法 上一篇我们学习了怎么发送各种数据类型的http请求&#xff0c;这一篇我们来介绍怎么来解析接口返回的XML的数据。 解析接口返回数据 定义结构体 假设我们现在有一个接口返回的数据resp如…

flutter 打包iOS安装包

flutter iOS Xcode打包并导出ipa文件安装包 1、 Xcode配置 1、 启动打包 1、 等待打包 1、 打包完成、准备导出ipa 1、 选择模式 1、 选择配置文件 1、 导出 1、 选择导出位置 1、 得到ipa

后台管理系统中常见的三栏布局总结:使用element ui构建

vue2 使用 el-menu构建的列表布局&#xff1a; 列表可以折叠展开 <template><div class"home"><header><el-button type"primary" click"handleClick">切换</el-button></header><div class"conte…

小研究 - 主动式微服务细粒度弹性缩放算法研究(三)

微服务架构已成为云数据中心的基本服务架构。但目前关于微服务系统弹性缩放的研究大多是基于服务或实例级别的水平缩放&#xff0c;忽略了能够充分利用单台服务器资源的细粒度垂直缩放&#xff0c;从而导致资源浪费。为此&#xff0c;本文设计了主动式微服务细粒度弹性缩放算法…

webpack联邦模块介绍及在dumi中使用问题整理

文章目录 前言一、ModuleFederationPlugin参数含义&#xff1f;二、如何在dumi中使用及问题整理1. 如何在dumi中使用(这个配置是好使的)2.相关问题整理2.1 问题12.2 问题2 总结 前言 联邦模块&#xff08;Module Federation&#xff09;是指一种用于构建微前端架构的技术&…

Vue3 导出word

&#x1f642;博主&#xff1a;锅盖哒 &#x1f642;文章核心&#xff1a;导出word 目录 1.首先&#xff0c;你需要安装docxtemplater库。可以使用npm或yarn来安装&#xff1a; 2.在Vue组件中&#xff0c;你可以使用docxtemplater来生成Word文档并提供一个导出按钮供用户下载…

[论文笔记] CLRerNet: Improving Confidence of Lane Detection with LaneIoU

Honda, Hiroto, and Yusuke Uchida. “CLRerNet: Improving Confidence of Lane Detection with LaneIoU.” arXiv preprint arXiv:2305.08366 (2023). 2023.05 出的一篇车道线检测的文章, 效果在CULane, CurveLanes SOTA 文章目录 简介LaneIoULineIoU存在问题为什么使用LaneIo…

Elasticsearch:通过动态修剪实现更快的基数聚合

作者&#xff1a;Adrien Grand Elasticsearch 8.9 通过支持动态修剪&#xff08;dynamic pruning&#xff09;引入了基数聚合加速。 这种优化需要满足特定的条件才能生效&#xff0c;但一旦实现&#xff0c;通常会产生惊人的结果。 我们观察到&#xff0c;通过此更改&#xff0…

微软对Visual Studio 17.7 Preview 4进行版本更新,新插件管理器亮相

近期微软发布了Visual Studio 17.7 Preview 4版本&#xff0c;而在这个版本当中&#xff0c;全新设计的扩展插件管理器将亮相&#xff0c;并且可以让用户可更简单地安装和管理扩展插件。 据了解&#xff0c;目前用户可以从 Visual Studio Marketplace 下载各式各样的 VS 扩展插…

【分布鲁棒、状态估计】分布式鲁棒优化电力系统状态估计研究[几种算法进行比较](Matlab代码实现)

&#x1f4a5;&#x1f4a5;&#x1f49e;&#x1f49e;欢迎来到本博客❤️❤️&#x1f4a5;&#x1f4a5; &#x1f3c6;博主优势&#xff1a;&#x1f31e;&#x1f31e;&#x1f31e;博客内容尽量做到思维缜密&#xff0c;逻辑清晰&#xff0c;为了方便读者。 ⛳️座右铭&a…

SpringBoot 8种异步实现方式

前言&#xff1a;异步执行对于开发者来说并不陌生&#xff0c;在实际的开发过程中&#xff0c;很多场景多会使用到异步&#xff0c;相比同步执行&#xff0c;异步可以大大缩短请求链路耗时时间&#xff0c;比如&#xff1a;「发送短信、邮件、异步更新等」&#xff0c;这些都是…

驱动开发 day3 (模块化驱动启动led,蜂鸣器,风扇,震动马达)

模块化驱动启动led,蜂鸣器,风扇,震动马达并加上Makefile 封装模块化驱动&#xff0c;可自由安装卸载驱动&#xff0c;便于驱动更新(附图) 1.安装模块驱动同时初始化各个设备并使能 2.该驱动会自动创建驱动节点. 3.通过c函数程序输入控制各个设备 4.卸载模块驱动 //编译驱动…

Python 日志记录:6大日志记录库的比较

Python 日志记录&#xff1a;6大日志记录库的比较 文章目录 Python 日志记录&#xff1a;6大日志记录库的比较前言一些日志框架建议1. logging - 内置的标准日志模块默认日志记录器自定义日志记录器生成结构化日志 2. Loguru - 最流行的Python第三方日志框架默认日志记录器自定…

Redis(五)—— Redis进阶部分

一、Redis配置文件详解 注意这是Redis服务本身的配置文件&#xff0c;相当于maven的settings.xml&#xff0c;而不是我们在springboot去配置Redis的那个application.yml。 核心部分include 引入其他redis配置文件&#xff0c;相当于spring的<import>bind 设置IP&#xf…

Spring MVC学习笔记,包含mvc架构使用,过滤器、拦截器、执行流程等等

&#x1f600;&#x1f600;&#x1f600;创作不易&#xff0c;各位看官点赞收藏. 文章目录 Spring MVC 习笔记1、Spring MVC demo2、Spring MVC 中常见注解3、数据处理3.1、请求参数处理3.2、响应数据处理 4、RESTFul 风格5、静态资源处理6、HttpMessageConverter 转换器7、过…

在周末,找回属于自己的时间~

&#x1f3c6;作者简介&#xff0c;黑夜开发者&#xff0c;全栈领域新星创作者✌&#xff0c;2023年6月csdn上海赛道top4。 &#x1f466;&#x1f3fb;个人主页 &#xff1a; 点击这里 &#x1f4bb;推荐专栏1&#xff1a;PHP面试题专区&#xff08;2023&#xff09; PHP入门基…

词典项目练习

思维导图 客户端 #include "head.h" //用户提示界面 void help_info1() {printf("\t-----------------------------------------------\n");printf("\t| HENRY 在线辞典 |\n");printf("\t|版本:0.0.1 …

Xamarin.Android实现加载中的效果

目录 1、说明2、代码如下2.1 图1的代码2.1.1、创建一个Activity或者Fragment&#xff0c;如下&#xff1a;2.1.2、创建Layout2.1.3、如何使用 2.2 图2的代码 4、其他补充4.1 C#与Java中的匿名类4.2 、其他知识点 5、参考资料 1、说明 在实际使用过程中&#xff0c;常常会用到点…

python和c加加有什么区别,c和c++和python先学哪个

本篇文章给大家谈谈c加加编程和python编程有什么区别&#xff0c;以及python和c加加有什么区别&#xff0c;希望对各位有所帮助&#xff0c;不要忘了收藏本站喔。 1、python和c学哪个好 学C好。 C通常比Python更快&#xff0c;因为C是一种编译型语言&#xff0c;而Python则是…
最新文章