Spring Boot自动装配原理以及实践

了解自动装配两个核心

@Import注解的作用

@Import说Spring框架经常会看到的注解,它有以下几个作用:

  1. 导入@Configuration类下所有的@bean方法中创建的bean
  2. 导入import指定的bean,例如@Import(AService.class),就会生成AServicebean,并将其导入到Spring容器中。
  3. 结合ImportSelector接口类导如指定类。(后文会展开介绍)

ImportSelector详解

ImportSelector接口则是前者的辅助者,如果我们希望可以选择性的导入一些类,我们就可以继承ImportSelector接口编写一个ImportSelector类,告知容器需要导入的类。就以Spring Boot为例,它有个@EnableAutoConfiguration注解,其工作原理就是基于内部的@Import({AutoConfigurationImportSelector.class})注解将AutoConfigurationImportSelector导入容器中,Spring就会调用其selectImports方法获取需要导入的类,并将这些类导入容器中。

@Override
	public String[] selectImports(AnnotationMetadata annotationMetadata) {
		if (!isEnabled(annotationMetadata)) {
			return NO_IMPORTS;
		}
		AutoConfigurationEntry autoConfigurationEntry = getAutoConfigurationEntry(annotationMetadata);
		//返回需要导入的类的字符串数组
		return StringUtils.toStringArray(autoConfigurationEntry.getConfigurations());
	}

使用示例

可能上文的原理对没有接触源码的读者比较模糊,所以我们不妨写一个demo来了解一下这个注解。我们现在有一个需求,希望通过import注解按需将Student类或者User类导入容器中。首先我们看看user类代码,没有任何实现,代码示例如下:

public class User {
}

Student 类代码同理,没有任何实现仅仅做测试使用

public class Student {
}

完成测试类的创建之后,我们就以用户类为例,创建UserConfig 代码如下:

@Configuration
public class UserConfig {

    @Bean
    public User getUser() {
        return new User();
    }
}

然后编写ImportSelector 首先类,编写自己的导入逻辑,可以看到笔者简单实现了一个selectImports方法返回UserConfig的类路径。

public class CustomImportSelector implements ImportSelector {

     private static Logger logger = LoggerFactory.getLogger(CustomImportSelector.class);

    /**
     * importingClassMetadata:被修饰的类注解信息
     */
    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {



        logger.info("获取到的注解类型:{}",importingClassMetadata.getAnnotationTypes().toArray());

        // 如果被CustomImportSelector导入的组件是类,那么我们就实例化UserConfig
        if (!importingClassMetadata.isInterface()) {
            return new String[] { "com.example.UserConfig" };
        }

        // 此处不要返回null
        return new String[] { "com.example.StudentConfig" };
    }
}

完成这些步骤我们就要来到最关键的一步了,在Spring Boot启动类中使用@Import导入CustomImportSelector

@SpringBootApplication
@Configuration
@Import(CustomImportSelector.class)
public class DemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);
	}

}

为了测试我们编写这样一个controller看看bean是否会导入到容器中

@RestController
public class MyController {

    private static Logger logger = LoggerFactory.getLogger(MyController.class);

    @Autowired
    private User user;

    @RequestMapping("hello")
    public String hello() {
        logger.info("user:{}", user);
        return "hello";
    }
}

结果测试我们发现user不为空,说明CustomImportSelector确实将UserConfig导入到容器中,并将User导入到容器中了。

从源码角度了解ImportSelector工作原理

关于源码分析其实也很好做,感兴趣的读者可以直接在CustomImportSelector打个断点就能知道工作原理了:

在这里插入图片描述

断点之后我们不妨用以终为始的方式了解一下过程,首先入口是AbstractApplicationContextrefresh()方法,它会调用一个invokeBeanFactoryPostProcessors(beanFactory);进行bean工厂后置操作

@Override
	public void refresh() throws BeansException, IllegalStateException {
		synchronized (this.startupShutdownMonitor) {
		.........
				invokeBeanFactoryPostProcessors(beanFactory);

			........

}
}

步入代码,可以看到容器会不断遍历各个postProcessor 即容器后置处理器,然后执行他们的逻辑

for (BeanFactoryPostProcessor postProcessor : beanFactoryPostProcessors) {
			.....
			//执行各个postProcessor 的逻辑
			invokeBeanDefinitionRegistryPostProcessors(currentRegistryProcessors, registry, beanFactory.getApplicationStartup());
}

重点来了,遍历过程中得到一个ConfigurationClassPostProcessor,这个类就会得到我们的CustomImportSelector,然后执行selectImports获取需要导入的类信息,最终会生成一个Set<ConfigurationClass> configClasses = new LinkedHashSet<>(parser.getConfigurationClasses());

如下图所示可以看到configClasses就包含UserConfig

在这里插入图片描述

总结一下核心流程的时序图

在这里插入图片描述

完成上述步骤后ConfigurationClassPostProcessor就会通过这个set集合执行loadBeanDefinitions方法将需要的bean导入到容器中,进行后续IOC操作。

在这里插入图片描述

上图代码如下所示:

//configClasses 中就包含了UserConfig类
Set<ConfigurationClass> configClasses = new LinkedHashSet<>(parser.getConfigurationClasses());
			configClasses.removeAll(alreadyParsed);

//执行	loadBeanDefinitions	
			this.reader.loadBeanDefinitions(configClasses);

Spring Boot自动装配原理(重点)

了解了import原理后,我们了解Spring Boot自动装配原理也很简单了,我们不妨看看Spring Boot@SpringBootApplication这个注解中包含一个@EnableAutoConfiguration注解,我们不妨点入看看,可以看到它包含一个@Import(AutoConfigurationImportSelector.class)注解,从名字上我们可以知晓这是一个ImportSelector的实现类。

所以我们不妨看看它的selectImports逻辑,可以看到它会通过getAutoConfigurationEntry方法获取需要装配的类,然后通过StringUtils.toStringArray切割返回。所以我们不妨看看getAutoConfigurationEntry

@Override
	public String[] selectImports(AnnotationMetadata annotationMetadata) {
		if (!isEnabled(annotationMetadata)) {
			return NO_IMPORTS;
		}
		AutoConfigurationEntry autoConfigurationEntry = getAutoConfigurationEntry(annotationMetadata);
		return StringUtils.toStringArray(autoConfigurationEntry.getConfigurations());
	}

查看getAutoConfigurationEntry方法,我们可以看到它通过getCandidateConfigurations获取各个xxxxAutoConfigure,并返回结果

protected AutoConfigurationEntry getAutoConfigurationEntry(AnnotationMetadata annotationMetadata) {
		if (!isEnabled(annotationMetadata)) {
			return EMPTY_ENTRY;
		}
		AnnotationAttributes attributes = getAttributes(annotationMetadata);
		//获取所有xxxxAutoConfigure
		List<String> configurations = getCandidateConfigurations(annotationMetadata, attributes);
		//移除不需要的
		configurations = removeDuplicates(configurations);
		Set<String> exclusions = getExclusions(annotationMetadata, attributes);
		checkExcludedClasses(configurations, exclusions);
		configurations.removeAll(exclusions);
		configurations = getConfigurationClassFilter().filter(configurations);
		fireAutoConfigurationImportEvents(configurations, exclusions);
		//返回结果
		return new AutoConfigurationEntry(configurations, exclusions);
	}

在这里插入图片描述

getCandidateConfigurations实际上是会通过一个loadSpringFactories方法,如下所示遍历获取所有含有META-INF/spring.factoriesjar

private static Map<String, List<String>> loadSpringFactories(ClassLoader classLoader) {
        Map<String, List<String>> result = (Map)cache.get(classLoader);
        if (result != null) {
            return result;
        } else {
            HashMap result = new HashMap();

            try {
            //解析这个配置文件获取所有配置类然后返回
                Enumeration urls = classLoader.getResources("META-INF/spring.factories");

              .....
                return result;
            } catch (IOException var14) {
                throw new IllegalArgumentException("Unable to load factories from location [META-INF/spring.factories]", var14);
            }
        }
    }

最终结果过滤解析,回到我们上文说的beanDefinitionMap中,最终通过IOC完成自动装配。

实践1-手写Spring Boot Starter中间件

了解自动装配我们不妨自己写一个中间件实践一下,现在需求如下,我们希望某些类的接口只有某几个用户可以访问,所以我们希望编写一个中间件判断请求用户是什么身份,如果没有权限则直接返回报错。

首先我们编写一个注解DoDoor ,用key记录传入的用户idreturnJson返回没有权限的响应结果

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface DoDoor {

    String key() default "";

    String returnJson() default "";

}

然后在编写StarterServiceProperties ,使用ConfigurationPropertiesitstack.door前缀的值和当前类userStr绑定。

/**
 * 通过"itstack.door前缀的配置获取userStr信息
 */
@ConfigurationProperties("itstack.door")
public class StarterServiceProperties {

    private String userStr;

    public String getUserStr() {
        return userStr;
    }

    public void setUserStr(String userStr) {
        this.userStr = userStr;
    }

}

完成后在编写StarterService 这个类会将userStr切割成数组,例如我们传111,222,最终就会得到[111,222]

public class StarterService {

    private String userStr;

    public StarterService(String userStr) {
        this.userStr = userStr;
    }

    public String[] split(String separatorChar) {
        return StringUtils.split(this.userStr, separatorChar);
    }

}

这些佐料写完之后,我们就可以编写一个AOP类了,可以看到这个AOP做的是很简单,就是拦截带有DoDoor的请求,将注解key配置的值和我们的userStr数组比对,若包含则放行,反之拦截。

@Aspect
@Component
public class DoJoinPoint {

    private Logger logger = LoggerFactory.getLogger(DoJoinPoint.class);

    @Autowired
    private StarterService starterService;

    @Pointcut("@annotation(org.itstack.door.annotation.DoDoor)")
    public void aopPoint() {
    }

    @Around("aopPoint()")
    public Object doRouter(ProceedingJoinPoint jp) throws Throwable {
        //获取内容
        Method method = getMethod(jp);
        DoDoor door = method.getAnnotation(DoDoor.class);
        //获取字段值
        String keyValue = getFiledValue(door.key(), jp.getArgs());
        logger.info("itstack door handler method:{} value:{}", method.getName(), keyValue);
        if (null == keyValue || "".equals(keyValue)) return jp.proceed();
        //配置内容
        String[] split = starterService.split(",");
        //白名单过滤
        for (String str : split) {
            if (keyValue.equals(str)) {
                return jp.proceed();
            }
        }
        //拦截
        return returnObject(door, method);
    }

    private Method getMethod(JoinPoint jp) throws NoSuchMethodException {
        Signature sig = jp.getSignature();
        MethodSignature methodSignature = (MethodSignature) sig;
        return getClass(jp).getMethod(methodSignature.getName(), methodSignature.getParameterTypes());
    }

    private Class<? extends Object> getClass(JoinPoint jp) throws NoSuchMethodException {
        return jp.getTarget().getClass();
    }

    //返回对象
    private Object returnObject(DoDoor doGate, Method method) throws IllegalAccessException, InstantiationException {
        Class<?> returnType = method.getReturnType();
        String returnJson = doGate.returnJson();
        if ("".equals(returnJson)) {
            return returnType.newInstance();
        }
        return JSON.parseObject(returnJson, returnType);
    }

    //获取属性值
    private String getFiledValue(String filed, Object[] args) {
        String filedValue = null;
        for (Object arg : args) {
            try {
                if (null == filedValue || "".equals(filedValue)) {
                    filedValue = BeanUtils.getProperty(arg, filed);
                } else {
                    break;
                }
            } catch (Exception e) {
                if (args.length == 1) {
                    return args[0].toString();
                }
            }
        }
        return filedValue;
    }

}

编写我们的AutoConfigure ,根据条件决定上述的类是否导入

@Configuration
@ConditionalOnClass(StarterService.class)
@EnableConfigurationProperties(StarterServiceProperties.class)
public class StarterAutoConfigure {

    @Autowired
    private StarterServiceProperties properties;

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "itstack.door", value = "enabled", havingValue = "true")
    StarterService starterService() {
        return new StarterService(properties.getUserStr());
    }

    @Bean
    @ConditionalOnMissingBean
    @ConditionalOnProperty(prefix = "itstack.door", value = "enabled", havingValue = "true")
    DoJoinPoint doJoinPoint() {
        return new DoJoinPoint();
    }

}

完成后编写一个spring.factories,导入这个AutoConfigure

org.springframework.boot.autoconfigure.EnableAutoConfiguration=org.itstack.door.config.StarterAutoConfigure

修改一下pom,本地打个包

<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-aop</artifactId>
</dependency>
		
<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-jar-plugin</artifactId>
	<version>2.3.2</version>
	<configuration>
		<archive>
			<addMavenDescriptor>false</addMavenDescriptor>
			<index>true</index>
			<manifest>
				<addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
				<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
			</manifest>
			<manifestEntries>
				<Implementation-Build>${maven.build.timestamp}</Implementation-Build>
			</manifestEntries>
		</archive>
	</configuration>
</plugin>			

在其他应用中导入

<dependency>
			<groupId>org.itatack.demo</groupId>
			<artifactId>door-spring-boot-starter</artifactId>
			<version>1.0.1-SNAPSHOT</version>
		</dependency>

编写配置

server:
  port: 9887

spring:
  application:
    name: demo

# 自定义中间件配置
itstack:
  door:
    enabled: true
    userStr: 1001,aaaa,ccc #白名单用户ID,多个逗号隔开

然后在导入这个中间件的应用中编写一个方法测试@DoDoor

@RestController
public class HelloWorldController {
    @Autowired
    private ApplicationContext applicationContext;

    @DoDoor(key = "userId", returnJson = "{\"code\":\"1111\",\"info\":\"非白名单可访问用户拦截!\"}")
    @RequestMapping(path = "/user", method = RequestMethod.GET)
    public Map queryUserInfo(@RequestParam String userId) {
        Map<String, DoJoinPoint> beansOfType = applicationContext.getBeansOfType(DoJoinPoint.class);
        Map resultMap = new HashMap<>();
        resultMap.put("虫虫:" + userId, "天津市南开区旮旯胡同100号");
        return resultMap;
    }

}

测试结果

C:\Users\xxxx>curl http://localhost:9887/user?userId=1001132
{"code":"1111","info":"非白名单可访问用户拦截!"}
C:\Users\xxx>curl http://localhost:9887/user?userId=1111
{"code":"1111","info":"非白名单可访问用户拦截!"}
C:\Users\xx>curl http://localhost:9887/user?userId=1001
{"虫虫:1001":"天津市南开区旮旯胡同100号"}

源码是借鉴小傅哥的,感兴趣的读者可以参考:

Spring Boot 中间件开发(一)《服务治理中间件之统一白名单验证》

实践2-通用日志组件

需求介绍

微服务项目中,基于日志排查问题是非常重要的手段,而日志属于非功能范畴的一个职责,所以我们希望将日志打印和功能解耦。AOP就是非常不错的手段,但是在每个服务中都编写一个切面显然是非常不可取的。
所以我们希望通过某种手段会编写一个通用日志打印工具,只需一个注解即可实现对方法的请求响应进行日志打印。
所以我们这个例子仍然是利用自动装配原理编写一个通用日志组件。

实现步骤

  1. 创建日志插件模块cloud-component-logging-starter,并引入我们需要的依赖,如下所示,因为笔者要对spring-web应用进行拦截所以用到的starter-webaop模块,以及为了打印响应结果,笔者也用到hutool,完整的依赖配置如下所示:
 <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-aop</artifactId>
        </dependency>


        <dependency>
            <groupId>cn.hutool</groupId>
            <artifactId>hutool-all</artifactId>
        </dependency>
    </dependencies>
  1. 编写日志注解,如下所示,该注解的value用于记录当前方法要执行的操作,例如某方法上@SysLog("获取用户信息"),当我们的aop拦截到之后,就基于该注解的value打印该方法的功能。
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface SysLog {
    /**
     * 记录方法要执行的操作
     *
     * @return
     */
    String value();
}

  1. 编写环绕切面逻辑,代码如下所示,逻辑非常简单,拦截到了切面后若报错则打印报错的逻辑,反之打印正常请求响应结果。
@Aspect
public class SysLogAspect {

     private static Logger logger = LoggerFactory.getLogger(SysLogAspect.class);

    @Pointcut("@annotation(com.zsy.annotation.SysLog)")
    public void logPointCut() {

    }


    @Around("logPointCut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        MethodSignature signature = (MethodSignature) joinPoint.getSignature();
        Method method = signature.getMethod();
        //类名
        String className = joinPoint.getTarget().getClass().getName();
        //方法名
        String methodName = signature.getName();

        SysLog syslog = method.getAnnotation(SysLog.class);
        //获取当前方法进行的操作
        String operator =syslog.value();

        long beginTime = System.currentTimeMillis();

        Object returnValue = null;
        Exception ex = null;
        try {
            returnValue = joinPoint.proceed();
            return returnValue;
        } catch (Exception e) {
            ex = e;
            throw e;
        } finally {
            long cost = System.currentTimeMillis() - beginTime;
            if (ex != null) {
                logger.error("业务请求:[类名: {}][执行方法: {}][执行操作: {}][耗时: {}ms][请求参数: {}][发生异常]",
                        className, methodName, operator, joinPoint.getArgs(), ex);
            } else {
                logger.info("业务请求:[类名: {}][执行方法: {}][执行操作: {}][耗时: {}ms][请求参数: {}][响应结果: {}]",
                        className, methodName, operator, cost, joinPoint.getArgs(), JSONUtil.toJsonStr(returnValue));
            }
        }

    }
}
  1. 编写配置类
@Configuration
public class SysLogAutoConfigure {

    @Bean
    public SysLogAspect getSysLogAspect() {
        return new SysLogAspect();
    }
}

  1. 新建spring.factories告知要导入Spring容器的类,内容如下
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.zsy.config.SysLogAutoConfigure
  1. 其他服务引入进行测试,以笔者为例,方法如下
@SysLog("获取用户信息")
    @GetMapping("getByCode/{accountCode}")
    public ResultData<AccountDTO> getByCode(@PathVariable(value = "accountCode") String accountCode) {
        log.info("远程调用feign接口,请求参数:{}", accountCode);
        return accountFeign.getByCode(accountCode);
    }

请求之后输出结果如下

2023-02-16 00:08:08,085 INFO  SysLogAspect:58 - 业务请求:[类名: com.zsy.order.controller.OrderController][执行方法: getByCode][执行操作: 获取用户信息][耗时: 892ms][请求参数: [zsy]][响应结果: {"data":{"accountCode":"zsy","amount":10000,"accountName":"zsy","id":1},"message":"操作成功","success":true,"status":100,"timestamp":1676477287856}]

参考文献

SpringBoot 自动装配原理

@Import、ImportSelector注解使用及源码分析

SpringBoot封装我们自己的Starter

Spring Boot 中间件开发(一)《服务治理中间件之统一白名单验证》

SpringCloud Alibaba微服务实战三十一 - 业务日志组件

Spring全解系列 - @Import注解

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

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

相关文章

如何实现公网访问本地内网搭建的WBO白板远程协作办公【内网穿透】

最近&#xff0c;我发现了一个超级强大的人工智能学习网站。它以通俗易懂的方式呈现复杂的概念&#xff0c;而且内容风趣幽默。我觉得它对大家可能会有所帮助&#xff0c;所以我在此分享。点击这里跳转到网站。 文章目录 前言1. 部署WBO白板2. 本地访问WBO白板3. Linux 安装cp…

mipi屏幕的供电和背光ledk

目录 屏幕供电 背光供电 屏幕供电 mipi的高通供电主要是2.8V和1.8V两个屏幕供电 author daisy.skye的博客_CSDN博客-嵌入式,Qt,Linux领域博主 https://blog.csdn.net/qq_40715266?typeblog 供电配置路径 kernel/msm-3.18/arch/arm/boot/dts/P322/msm8953-mdss-panels.dtsi …

Kubernetes - Dashboard Token 访问登录永不过期配置

如图查看 1 2 3 4 步骤 选择 dashboard 的命名空间&#xff0c;有些版本估计在 kube-system&#xff0c;具体情况具体分析选择 Deployments找到对应 kubernetes-dashboard编辑 yml 添加配置项 - --token-ttl0 需要重新大刷下&#xff0c;重新登录下即可~

用Python完成下列问题。给你一个非空整数列表,除了某个元素只出现一次以外,其余每个元素均出现两次。找出那个只出现了一次的元素。

用Python完成下列问题。给你一个非空整数列表&#xff0c;除了某个元素只出现一次以外&#xff0c;其余每个元素均出现两次。找出那个只出现了一次的元素。 示例 1 &#xff1a; 输入&#xff1a;nums [2,2,1]输出&#xff1a;1 示例 2 &#xff1a; 输入&#xff1a;nums [4…

Vue3创建应用教程

前提条件&#xff1a; 熟悉命令行已安装 16.0 或更高版本的 Node.js 命令行 在当前工作目录输入cmd打开命令行窗口在命令行窗口输入(不需要输入>号&#xff09; 这一指令将会安装并执行 create-vue&#xff0c;它是 Vue 官方的项目脚手架工具。你将会看到一些诸如 TypeScr…

PageView组件实现翻页和自定义轮播图

PageView实现上下翻页 import package:flutter/material.dart; import package:flutter/services.dart; import package:flutter_demo/tools/pageViewKeepAlive.dart;void main() {//设置状态栏颜色SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(statusBar…

实现Springboot的自动装配

首先我们有一个模块叫testOne 该模块就只定义一个类UserService。 我们要将UserService自动装配到Springboot中。 一下是testOne的各个文件。 pom.xml <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM…

LinuxCNC的使用

先进行程序设置 点击“开始”,选择“创建新的配置” 设置好机床名称和单位 关键是需要设置并口地址 查看并口使用命令:lscpi -v 将使用的并口填入: 这里是设置页面

Cesium 展示——实现球体和背景分离

文章目录 需求分析补充:添加监听让Cesium随窗口大小自适应需求 页面本身body有一个背景,想要只加载cesium球体,而背景设为透明,露出body的背景,有没有方法实现呢 注意:图片是随机找的一张 分析 html<!-- Cesium --> <divid="cesiumContainer"style…

MySQL通过Binlog日志恢复数据库

一、MySQL Binlog 简介 MySQL 的二进制日志 binlog 可以说是 MySQL 最重要的日志&#xff0c;它记录了所有的 DDL 和 DML 语句&#xff08;除了数据查询语句select、show等&#xff09;&#xff0c;以事件形式记录&#xff0c;还包含语句所执行的消耗的时间&#xff0c;MySQL的…

onnx 图像分类

参考文章&#xff1a; 【netron】模型可视化工具netron-CSDN博客 Pytorch图像分类模型部署-ONNX Runtime本地终端推理_哔哩哔哩_bilibili 使用netron可视化模型结构 1&#xff09;使用在线版 浏览器访问&#xff1a;Netron 点击 “Open Model” 按钮&#xff0c;选择要可…

数据库灾难应对:MySQL误删除数据的救赎之道,技巧get起来!之binlog

《数据库灾难应对&#xff1a;MySQL误删除数据的救赎之道&#xff0c;技巧get起来&#xff01;之binlog》 数据意外删除是数据库管理中常见的问题之一。MySQL作为广泛使用的数据库管理系统&#xff0c;当数据意外删除时&#xff0c;有几种方法可以尝试恢复数据。以下是binlog方…

基于SpringBoot的房屋租赁系统 附源码

基于SpringBoot的房屋租赁系统 附源码 文章目录 基于SpringBoot的房屋租赁系统 附源码 一.引言二.系统设计三.技术架构四.功能实现五.界面展示六.源码获取 一.引言 本文介绍了一个基于SpringBoot的房屋租赁系统。该系统利用SpringBoot框架的优势&#xff0c;实现了用户注册、登…

采购oled屏幕,应注意什么

在采购OLED屏幕时&#xff0c;应注意以下几点&#xff1a; 规格和参数&#xff1a;了解OLED屏幕的规格和参数&#xff0c;包括尺寸、分辨率、亮度、对比度、响应时间等。确保所采购的屏幕符合项目的需求和预期效果。 品质和可靠性&#xff1a;选择具有可靠品质和稳定性的OLED屏…

分布式事务seata使用示例及注意事项

分布式事务seata使用示例及注意事项 示例说明代码调用方&#xff08;微服务A&#xff09;服务方&#xff08;微服务B&#xff09; 测试测试一 &#xff0c;seata发挥作用&#xff0c;成功回滚&#xff01;测试二&#xff1a;处理feignclient接口的返回类型从Integer变成String,…

Ngnix之反向代理、负载均衡、动静分离

目录 1. Ngnix 1.1 Linux系统Ngnix下载安装 1.2 反向代理 正向代理&#xff08;Forward Proxy&#xff09;&#xff1a; 反向代理&#xff08;Reverse Proxy&#xff09;&#xff1a; 1.3 负载均衡 1.4 动静分离 1. Ngnix Nginx是一个高性能的开源Web服务器&#xff0…

python识别增强静脉清晰度 opencv-python图像处理案例

一.任务说明 用python实现静脉清晰度提升。 二.代码实现 import cv2 import numpy as npdef enhance_blood_vessels(image):# 调整图像对比度和亮度enhanced_image cv2.convertScaleAbs(image, alpha0.5, beta40)# 应用CLAHE&#xff08;对比度受限的自适应直方图均衡化&…

Future CompleteFuture

前言 Java8 中的 completeFuture 是对 Future 的扩展实现&#xff0c;主要是为了弥补 Future 没有相应的回调机制的缺陷。 Callable、Runnable、Future、CompletableFuture 之间的关系&#xff1a; Callable&#xff0c;有结果的同步行为&#xff0c;比如做蛋糕&#xff0c;…

python程序打包成exe全流程纪实(windows)

目录 前言准备工作安装python&#xff08;必须&#xff09;安装vs平台或conda&#xff08;非必须&#xff09; 详细步骤Step1.创建python虚拟环境方法一、裸装(windows下)方法二、借助工具(windows下) Step2.安装打包必须的python包Step3.准备好程序logo&#xff08;非必须&…

51单片机定时器

51单片机有两个16位定时器&#xff0c;今天复习了一下使用方法&#xff0c;发现当初刚开始学习51单片机时并没有记录&#xff0c;特此今天补上这篇博客。 下面是定时器的总览示意图&#xff0c;看到这个图就能想到定时器怎么设置&#xff0c;怎么开始工作。 第一步&#xff1a…