Spring 依赖查找知识点总结
前言
源码在我github的guide-spring仓库中,可以克隆下来 直接执行。
我们本文主要来介绍依赖查找
的使用示例
依赖查找
什么是依赖查找
依赖查找并不是 Spring 框架特有的概念,它是一种在软件开发中获取依赖对象的方式。它通常用于获取运行时需要的服务、组件或其他对象的引用。在面向对象编程中,依赖通常体现为一个对象需要另一个对象的服务或功能。
在不同的编程框架和容器中,依赖查找的方式可能会有所不同。我们简单罗列一些常见的依赖查找的例子:
Java中的依赖查找
- 在纯 Java 环境中,依赖查找通常通过构造函数、方法参数或其他手段来获得依赖对象的引用。
- 例如,通过在一个对象的构造函数中传递另一个对象的引用:
public class MyClass {private DependencyClass dependency;public MyClass(DependencyClass dependency) {this.dependency = dependency;}// ...
}
Spring框架中的依赖查找
-
在Spring框架中,依赖查找通常通过 Spring 容器来实现。你可以使用
ApplicationContext
orBeanFactory
来获取所需的 Bean 。public class UseDependencyLookupDemo {public static void main(String[] args) throws Exception {BeanFactory beanFactory = new ClassPathXmlApplicationContext("classpath:/META-INF/dependency-lookup.xml");// 1. 实时查找realtimeLookup(beanFactory);}private static void realtimeLookup(BeanFactory beanFactory) {// 名称+类型User user = beanFactory.getBean("user", User.class);System.out.println("实时查找: " + user);} }
-
或者,通过在类中使用
@Autowired
注解来自动注入依赖:@Service public class MyService {@Autowiredprivate DependencyClass dependency;// ... }
Java EE中的依赖查找:
-
在Java EE环境中,你可以使用JNDI(Java Naming and Directory Interface)进行依赖查找。通过JNDI,你可以在运行时查找和获取命名对象。
public class JNDIDependencyLookupDemo {public static void main(String[] args) throws NamingException {// 设置JNDI环境属性Properties properties = new Properties();properties.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory");properties.put(Context.PROVIDER_URL, "file:/META-INF/jndi");// 初始化InitialContextContext initialContext = new InitialContext(properties);// 在文件系统上查找一个名为 "user" 的对象User user = (User) initialContext.lookup("user");System.out.println("JNDI Lookup Result: " + user);} }
依赖查找的方式
依赖查找的方式有很多,我们先看下 BeanFactory 的 接口定义:
public interface BeanFactory {Object getBean(String name) throws BeansException;<T> T getBean(String name, Class<T> requiredType) throws BeansException;<T> T getBean(Class<T> requiredType) throws BeansException;<T> ObjectProvider<T> getBeanProvider(Class<T> requiredType);<T> ObjectProvider<T> getBeanProvider(ResolvableType requiredType);}
可以看出上述定义,我们可以通过 Bean 名称、Bean 名称 + 类型、类型等方式进行依赖查找 Bean。下面我们分别从单一类型、集合类型、层次类型、延迟等方式依次展示依赖查找的示例。
单一类型的依赖查找
单一类型的查找,需要要求容器中同一类型的Bean只能有一个为 primary (BeanDefinition中的概念),我们可以看下 xml 配置示例
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="user" class="com.markus.spring.ioc.overview.domain.User"><property name="id" value="1"/><property name="username" value="markus zhang"/></bean><!-- 当有多个 User 时,需要指出 其中一个 Bean 的 primary属性为 true 否则会出现 NoUniqueBeanDefinitionException --><bean id="user2" class="com.markus.spring.ioc.overview.domain.User" lazy-init="true" primary="true"><property name="id" value="2"/><property name="username" value="markus zhang"/></bean></beans>
我们来看下使用示例
public class UseDependencyLookupDemo {public static void main(String[] args) throws Exception {BeanFactory beanFactory = new ClassPathXmlApplicationContext("classpath:/META-INF/dependency-lookup.xml");typeLookup(beanFactory);}/*** ========================按照 Bean 类型查找========================*//*** 单个Bean类型查找** @param beanFactory*/private static void typeLookup(BeanFactory beanFactory) {User user = beanFactory.getBean(User.class);System.out.println(user);}
}
集合类型的依赖查找
与单一类型查找的区别在于,它不需要指定 primary 并且 返回一个 Map<String,T> 对象,key 为 Bean 的名称,value 为 Bean 实例。
public class UseDependencyLookupDemo {public static void main(String[] args) throws Exception {BeanFactory beanFactory = new ClassPathXmlApplicationContext("classpath:/META-INF/dependency-lookup.xml");// 4. 按照类型查找多个BeancollectionLookup(beanFactory);}/*** 根据集合类型查找*/private static void collectionLookup(BeanFactory beanFactory) {if (beanFactory instanceof ListableBeanFactory) {ListableBeanFactory listableBeanFactory = (ListableBeanFactory) beanFactory;Map<String, User> userMap = listableBeanFactory.getBeansOfType(User.class);userMap.forEach((beanName, user) -> System.out.println("Bean name: " + beanName + ", User: " + user));}}
}
层次类型的依赖查找
层次性依赖查找,体现在父子容器中,我们一般可能体会不到,实际上 Spring MVC 的底层就涉及父子容器的概念,即 Root ApplicationContext 和 Dispatcher-Servlet ApplicationContext。这里不展开了。我们通过一个简单的示例来展示层次性依赖查找 Bean
package com.markus.spring.dependency.lookup;import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.HierarchicalBeanFactory;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionReader;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;/*** @author: markus* @date: 2023/12/17 10:23 PM* @Description: {@link HierarchicalBeanFactory}* @Blog: https://markuszhang.com* It's my honor to share what I've learned with you!*/
public class HierarchicalBeanFactoryDependencyDemo {public static void main(String[] args) {ConfigurableListableBeanFactory subBeanFactory = new DefaultListableBeanFactory();// 设置父容器subBeanFactory.setParentBeanFactory(createParent());// 展示 仅在当前 Bean 容器中是否 存在System.out.println(displayContainBean(subBeanFactory, "user", true));// 展示 父子 Bean 容器中是否 存在(体现出 可继承 BeanFactory 的示例 即 HierarchicalBeanFactory)System.out.println(displayContainBean(subBeanFactory, "user", false));}private static boolean displayContainBean(ConfigurableListableBeanFactory beanFactory, String beanName, boolean onlyLocal) {boolean result = beanFactory.containsLocalBean(beanName);if (!onlyLocal) {if (!result) {BeanFactory parentBeanFactory = beanFactory.getParentBeanFactory();if (parentBeanFactory != null) {result = parentBeanFactory.containsBean(beanName);}}}return result;}private static ConfigurableListableBeanFactory createParent() {ConfigurableListableBeanFactory parentBeanFactory = new DefaultListableBeanFactory();BeanDefinitionReader beanDefinitionReader = new XmlBeanDefinitionReader((BeanDefinitionRegistry) parentBeanFactory);String location = "classpath:/META-INF/dependency-lookup.xml";// 加载 父容器 的 Bean 实例beanDefinitionReader.loadBeanDefinitions(location);return parentBeanFactory;}
}
延迟依赖查找
延迟依赖查找通常体现在懒加载 Bean 的场景,比如一些大资源的Bean希望在使用到的时候才会触发初始化以达到降低服务启动时间的目的,这个时候就可以使用懒加载模式,而在我们依赖查找的时候,使用延迟依赖查找的时候,也不会触发 Bean 的初始化,只有在真正使用到对象的时候才会触发初始化。(ps 比较绕,我们直接看例子)
因为 Bean 元信息配置比较特殊,我把 xml 配置也展示出来
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsd"><bean id="user2" class="com.markus.spring.ioc.overview.domain.User" lazy-init="true" primary="true"><property name="id" value="2"/><property name="username" value="markus zhang"/></bean><bean id="factoryBean" class="org.springframework.beans.factory.config.ObjectFactoryCreatingFactoryBean"><property name="targetBeanName" value="user2"/></bean></beans>
使用示例
public class UseDependencyLookupDemo {public static void main(String[] args) throws Exception {BeanFactory beanFactory = new ClassPathXmlApplicationContext("classpath:/META-INF/dependency-lookup.xml");lazyLookup(beanFactory);}/*** 延迟查找*/private static void lazyLookup(BeanFactory beanFactory) throws Exception {@SuppressWarnings("unchecked")ObjectFactory<User> factoryBean = (ObjectFactory<User>) beanFactory.getBean("factoryBean");System.out.println("延迟生效中....");System.out.println("延迟查找: " + factoryBean.getObject());}}
Spring内建可查找的依赖
除了我们自己配置的Bean,我们还可以查找 Spring 框架内 注册的单例 Bean。具体如下:
- environment Environment 外部化配置以及Profiles
- systemProperties Properties Java系统属性
- systemEnvironment Map<String,String> 操作系统环境变量
- messageSource MessageSource 国家化文案
- lifecycleProcessor LifecycleProcessor Lifecycle Bean 处理器
- applicationEventMulticaster ApplicationEventMulticaster Spring 事件广播器
- internalConfigurationAnnotationProcessor ConfigurationClassPostProcessor 处理 Spring 的配置类
- internalAutowiredAnnotationProcessor AutowiredAnnotationBeanPostProcessor 处理 @Autowired 以及 @Value、@Inject注解
- internalCommonAnnotationProcessor CommonAnnotationBeanPostProcessor 处理 JSR-250 注解,如 @Resource、@PostConstruct等
- internalEventListenerProcessor EventListenerMethodProcessor 处理标注 @EventListener 的 Spring 事件监听方法
- internalEventListenerFactory DefaultEventListenerFactory 处理@EventListener 事件监听方法适配为 ApplicationListener
我们来看下示例:
package com.markus.spring.dependency.lookup;import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.LifecycleProcessor;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.CommonAnnotationBeanPostProcessor;
import org.springframework.context.annotation.ConfigurationClassPostProcessor;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.context.event.DefaultEventListenerFactory;
import org.springframework.context.event.EventListenerMethodProcessor;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.env.Environment;import java.util.Properties;/*** @author: markus* @date: 2023/12/17 10:54 PM* @Description: Spring 内建依赖的 依赖查找示例* @Blog: https://markuszhang.com* It's my honor to share what I've learned with you!*/
public class SpringInternalBeanDependencyLookDemo {public static void main(String[] args) {ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("classpath:/META-INF/dependency-lookup.xml");displaySpringInternalBean(context, Environment.class);displaySpringInternalBean(context, Properties.class);displaySpringInternalBeanByName(context, "systemEnvironment");displaySpringInternalBean(context, MessageSource.class);displaySpringInternalBean(context, LifecycleProcessor.class);displaySpringInternalBean(context, ApplicationEventMulticaster.class);// 关闭 Spring 容器上下文context.close();// 基于 注解驱动 的应用上下文AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext();annotationConfigApplicationContext.register(SpringInternalBeanDependencyLookDemo.class);annotationConfigApplicationContext.refresh();displaySpringInternalBean(annotationConfigApplicationContext, ConfigurationClassPostProcessor.class);displaySpringInternalBean(annotationConfigApplicationContext, AutowiredAnnotationBeanPostProcessor.class);displaySpringInternalBean(annotationConfigApplicationContext, CommonAnnotationBeanPostProcessor.class);displaySpringInternalBean(annotationConfigApplicationContext, EventListenerMethodProcessor.class);displaySpringInternalBean(annotationConfigApplicationContext, DefaultEventListenerFactory.class);annotationConfigApplicationContext.close();}private static void displaySpringInternalBean(ApplicationContext context, Class<?> type) {Object bean = context.getBean(type);System.out.println(bean);}private static void displaySpringInternalBeanByName(ApplicationContext context, String beanName) {Object bean = context.getBean(beanName);System.out.println(bean);}
}
可以看到上面我们引入了基于 Xml 驱动的Spring应用上下文以及基于 注解 驱动的Spring应用上下文来实现 Spring 内建 Bean 的依赖查找。
ps: 如果一个默认的 ClassPathXmlAppplicationContext 不会包含ConfigurationClassPostProcessor、AutowiredAnnotationBeanPostProcessor等这些注解的依赖,需要我们在 xml 配置文件中开启 注解启动,才会注册进 Spring IoC容器中。
大家可能会有疑问,这些 Spring 内建的 Bean 是什么时候被注册进去呢?这里给下源码位置,感兴趣的可以自行查看:
- org.springframework.context.support.AbstractApplicationContext#prepareBeanFactory
- org.springframework.context.annotation.AnnotationConfigUtils#registerAnnotationConfigProcessors(org.springframework.beans.factory.support.BeanDefinitionRegistry, java.lang.Object)
依赖查找的常见异常
下面这些就是场景的在使用依赖查找的时候可能会触发的异常,都是 BeansException 的子类型。场景比较清晰,这里就不写具体的示例了。
异常类型 | 触发条件 | 场景举例 |
---|---|---|
NoSuchBeanDefinitionException | 当查找 Bean 不存在于 IoC 容器 时 | BeanFactory#getBean |
NoUniqueBeanDefinitionException | 类型依赖查找时,IoC 容器存在多 个 Bean 实例 | BeanFactory#getBean(Class) |
BeanInstantiationException | 当 Bean 所对应的类型非具体类时 | BeanFactory#getBean |
BeanCreationException | 当 Bean 初始化过程中 | Bean 初始化方法执行异常时 |
BeanDefinitionStoreException | 当 BeanDefinition 配置元信息非 法时 | XML 配置资源无法打开时 |
本文总结
好了,到这就基本上把 Spring 依赖查找相关的知识点就总结完了,本文我们主要总结了依赖查找
的几种方式,包括单一类型、集合类型、层次性、延迟性以及 Spring 内建 Bean 的依赖查找,并给出了 Spring 内建 Bean 注册的源码位置,最后提到了依赖查找
的几个常见的异常,并给出了常见场景触发的条件。
关于 Spring 依赖 还有依赖注入、依赖来源等知识 后面会跟进梳理。
以上也是我在学习 Spring 时参考的资料并加上了自己的理解,如有错误,欢迎交流。
相关文章:

Spring 依赖查找知识点总结
前言 源码在我github的guide-spring仓库中,可以克隆下来 直接执行。 我们本文主要来介绍依赖查找的使用示例 依赖查找 什么是依赖查找 依赖查找并不是 Spring 框架特有的概念,它是一种在软件开发中获取依赖对象的方式。它通常用于获取运行时需要的服…...

html5新增特性
对于这行代码,要写在html页面的最前端: <!DOCTYPE html> 为什么要写在前面? 这是声明,是html5的新特性 对于html4来说,它有三种声明格式,而html5只需要统一声明,用来告诉浏览器文档使用…...

4、APScheduler: 详解Scheduler种类用法、常见错误与解决方法【Python3测试任务管理总结】
调度器(Scheduler)是将其他组件绑在一起的关键。通常在应用程序中只运行一个调度器。应用程序开发者通常不直接处理作业存储(job stores)、执行器(executors)或触发器(triggers)。相反,调度器提供了适当的接口来处理所有这些。通过调度器配置作业存储和执行器,以及添…...

微服务实战系列之ZooKeeper(实践篇)
前言 关于ZooKeeper,博主已完整的通过庖丁解牛式的“解法”,完成了概述。我想掌握了这些基础原理和概念后,工作的问题自然迎刃而解,甚至offer也可能手到擒来,真实一举两得,美极了。 为了更有直观的体验&a…...

C++ 开发中为什么要使用继承
为何继承 实验介绍 继承是 C++ 中的特性之一,使用继承能够有效减轻工作量,使得开发更加高效。 知识点 什么是继承为何继承继承的内容权限关键字什么是继承 生活中继承是指孩子继承父亲的财产等。C++ 使用了这一思想,却又与生活中的继承不一样。 在使用继承时,派生类是…...

2020蓝桥杯c组纸张大小
题目名字 纸张大小 题目链接 题意 给一张纸,通过不断折叠,求最终长宽,给十个数字,输入哪个数字就求哪次折叠的长宽,其实就是,每次折叠后长度的一半变为宽度,原来的宽度变成长度 思路 因为数字…...

【Image】图像处理
计算机视觉 CV Perception 如自动驾驶领域。 只要是从所谓的图像当中去抽取信息的过程,我们都叫做Perception。 视觉检测可以涵盖二维检测,如车辆、人和信号灯的检测。另外,还可以控制三维信息,直接在三维空间中操作数据。 SL…...

JAVA对文档加密
当 Word 文档中包含无法公开的机密信息时,我们可以对其进行加密,使其在没有密码的情况下无法打开。本文将向您介绍如何使用 Spire.Doc for Java 加密 Word 文档和移除 Word 密码保护。 加密 Word 文档删除 Word 密码保护 安装 Spire.Doc for Java 首先…...

EmbedAI:一个可以上传文件训练自己ChatGPT的AI工具,妈妈再也不用担心我的GPT不会回答问题
功能介绍: 个性化定制:提供灵活的训练选项,用户能够通过文件、网站、Notion文档甚至YouTube等多种数据源对ChatGPT进行训练,以满足不同领域和需求的个性化定制。广泛应用场景:ChatGPT支持多种用例,包括智能…...
runCatching异常捕获onSuccess/onFailure返回函数,Kotlin
runCatching异常捕获onSuccess/onFailure返回函数,Kotlin fun test(a: Int, b: Int) {runCatching {a / b}.onSuccess {println("onSuccess: $it")return ok(it)}.onFailure {println("onFailure: $it")return fail(it)} }fun ok(o: Any) {prin…...

IDEA报错处理
问题1 IDEA 新建 Maven 项目没有文件结构 pom 文件为空 将JDK换成1.8后解决。 网络说法:别用 java18,换成 java17 或者 java1.8 都可以,因为 java18 不是 LTS 版本,有着各种各样的问题。。...

使用动画曲线编辑器打造炫酷的3D可视化ACE
前言 在制作3D可视化看板时,除了精细的模型结构外,炫酷的动画效果也是必不可少的。无论是复杂的还是简单的动画效果,要实现100%的自然平滑都是具有挑战性的工作。这涉及到物理引擎的计算和对动画效果的数学建模分析。一般来说,只…...

使用 React 和 ECharts 创建地球模拟扩散和飞线效果
在本博客中,我们将学习如何使用 React 和 ECharts 创建一个酷炫的地球模拟扩散效果。我们将使用 ECharts 作为可视化库,以及 React 来构建我们的应用。地球贴图在文章的结尾。 最终效果 准备工作 首先,确保你已经安装了 React,并…...

http状态码(一)400报错
一 400报错汇总 ① 综述 一、4xx状态码报错说明: 客户端行为导致的报错二、通用的4xxHTTP报错1) 4002) 4013) 4034) 4045) 405 --> 不允许方法,可能跨域或者nginx限制请求方法6) 4087) 4138) 419三、ngin自身定义的4xx报错495、496、497、498、4…...

【深度学习目标检测】五、基于深度学习的安全帽识别(python,目标检测)
深度学习目标检测方法则是利用深度神经网络模型进行目标检测,主要有以下几种: R-CNN系列:包括R-CNN、Fast R-CNN、Faster R-CNN等,通过候选区域法生成候选目标区域,然后使用卷积神经网络提取特征,并通过分类…...

芒果RT-DETR改进实验:深度集成版目标检测 RT-DETR 热力图来了!支持自定义数据集训练出来的模型
💡该教程为改进RT-DETR指南,属于《芒果书》📚系列,包含大量的原创改进方式🚀 💡🚀🚀🚀内含改进源代码 按步骤操作运行改进后的代码即可💡更方便的统计更多实验数据,方便写作 芒果RT-DETR改进实验:深度集成版目标检测 RT-DETR 热力图来了!支持自定义数据集…...

c语言实验八
实验1:在主函数中输入num个字符串,写一个函数,从传入的num个字符串中找出最长的一个字符串,并通过形参指针max传回该串地址,在主函数中输出。(注意:用****作为结束输入的标志。) #i…...

ArcGIS Pro SDK文件选择对话框
文件保存对话框 // 获取默认数据库var gdbPath Project.Current.DefaultGeodatabasePath;//设置文件的保存路径SaveItemDialog saveLayerFileDialog new SaveItemDialog(){Title "Save Layer File",OverwritePrompt true,//获取或设置当同名文件已存在时是否出现…...

ACT、NAT、NATPT和EASY-IP
目录 一、ACL 1.ACL 2.ACL的两种应用匹配机制 3.ACL的基本类型 4.ACL命令操作 5.ACL实验: 4.ACL的应用原则: 5.匹配原则: 二、NAT 1.NAT的原理及作用: 2.NAT分类 3.NAT配置 三、EASY-ip实验 四、NATPT 五、通配符 …...

HTML实现每天单词积累
注册页面 <!DOCTYPE html> <html> <head><meta charset"UTF-8"><title>注册</title><style>body {font-family: Arial, sans-serif;background-color: #f5f5f5;}form {max-width: 500px;margin: 50px auto;padding: 40px…...

【ECMAScript笔记二】运算符分类,流程控制(顺序结构、分支结构、循环结构)
文章目录 4 运算符4.1 算术运算符4.2 递增和递减运算符4.3 比较运算符4.4 逻辑运算符4.5 赋值运算符4.6 运算优先级 5 流程控制5.1 顺序结构5.2 分支结构5.2.1 if 语句5.2.2 switch 语句 5.3 循环结构5.3.1 for循环5.3.2 while循环5.3.3 do while循环5.3.4 continue和break 5.4…...

ShenYu网关注册中心之Zookeeper注册原理
文章目录 1、客户端注册流程1.1、读取配置1.1.1、用于注册的 ZookeeperClientRegisterRepository1.1.2、用于扫描构建 元数据 和 URI 的 SpringMvcClientEventListener 1.2、扫描注解,注册元数据和URI1.2.1、构建URI并写入Disruptor1.2.2、构建元数据并写入Disrupto…...

高级C#技术(二)
前言 本章为高级C#技术的第二节也是最后一节。前一节在下面这个链接 高级C#技术https://blog.csdn.net/qq_71897293/article/details/134930989?spm1001.2014.3001.5501 匿名类型 匿名类型如其名,匿名的没有指定变量的具体类型。 举个例子: 1 创建…...

【性能测试】基础知识篇-压力模型
常见压力模式 并发模式(即虚拟用户模式)和RPS模式(即Requests Per Second,每秒请求数,吞吐量模式)。 本文介绍这两种压力模式的区别,以便根据自身业务场景选择更合适的压力模式。 并发模式 …...

springboot-redis设置定时触发任务详解
最近研究了一下“redis定时触发”,网上查了查资料,这里记录一下。 从Redis 2.8.0开始,Redis加入了发布/订阅模式以及键空间消息提醒(keyspace notification)功能。键空间消息提醒提供了允许客户端通过订阅指定信道获取…...

Video anomaly detection with spatio-temporal dissociation 论文阅读
Video anomaly detection with spatio-temporal dissociation 摘要1.介绍2.相关工作3. Methods3.1. Overview3.2. Spatial autoencoder3.3. Motion autoencoder3.4. Variance attention module3.5. Clustering3.6. The training objective function 4. Experiments5. Conclusio…...

svn 安装
安装系统 ubuntu 22 安装命令: sudo apt-get install subversion 创建第一个工程: 创建版本库、项目 1、先创建svn根目录文件夹 sudo mkdir /home/svn 2、创建项目的目录文件夹 sudo mkdir /home/svn/demo_0 svnadmin create /home/svn/demo_0 配置&a…...

slurm 23.11.0集群 debian 11.5 安装
slurm 23.11.0集群 debian 11.5 安装 用途 Slurm(Simple Linux Utility for Resource Management, http://slurm.schedmd.com/ )是开源的、具有容错性和高度可扩展的Linux集群超级计算系统资源管理和作业调度系统。超级计算系统可利用Slurm对资源和作业进行管理&a…...

ffmpeg可以做什么
用途 FFmpeg是一个功能强大的多媒体处理工具,可以处理音频和视频文件。它是一个开源项目,可在各种操作系统上运行,包括Linux、Windows和Mac OS X等。以下是FFmpeg可以做的一些主要任务: 转换媒体格式:可将一个媒体格式…...

一种缩小数据之间差距的算法
先上代码: /** * 缩小数据之间的差距,但是大小关系不变的方法* param {Array} features */function minMaxData(data) {for (let i 0; i < data.length; i) {const f data[i];const x f[1];const yf[2];//此处5根据实际情况设置const y2 Math.pow(…...