在复杂业务场景下,传统的单体应用架构往往面临着功能扩展困难、代码耦合严重、迭代效率低下等问题。

插件化架构作为一种模块化设计思想的延伸,能够使系统具备更好的扩展性和灵活性,实现"热插拔"式的功能扩展。

本文将介绍SpringBoot环境下实现插件化架构的4种实现方案。

方案一:基于Spring的条件注解实现

原理介绍

这种方案利用Spring提供的条件注解(如@Conditional@ConditionalOnProperty等)实现插件的动态加载。通过配置文件或环境变量控制哪些插件被激活,适合简单的插件化需求。

实现步骤

  1. 1. 定义插件接口

  2. 2. 实现多个插件实现类

  3. 3. 使用条件注解控制插件加载

  4. 4. 在主应用中使用插件

代码示例

1. 定义插件接口

public interface PaymentPlugin {String getName();boolean support(String payType);PaymentResult pay(PaymentRequest request);
}

2. 实现插件类

@Component
@ConditionalOnProperty(prefix = "plugins.payment", name = "alipay", havingValue = "true")
public class AlipayPlugin implements PaymentPlugin {@Overridepublic String getName() {return "alipay";}@Overridepublic boolean support(String payType) {return "alipay".equals(payType);}@Overridepublic PaymentResult pay(PaymentRequest request) {// 支付宝支付逻辑System.out.println("Processing Alipay payment");return new PaymentResult(true, "Alipay payment successful");}
}@Component
@ConditionalOnProperty(prefix = "plugins.payment", name = "wechat", havingValue = "true")
public class WechatPayPlugin implements PaymentPlugin {@Overridepublic String getName() {return "wechat";}@Overridepublic boolean support(String payType) {return "wechat".equals(payType);}@Overridepublic PaymentResult pay(PaymentRequest request) {// 微信支付逻辑System.out.println("Processing WeChat payment");return new PaymentResult(true, "WeChat payment successful");}
}

3. 插件管理器

@Component
public class PaymentPluginManager {private final List<PaymentPlugin> plugins;@Autowiredpublic PaymentPluginManager(List<PaymentPlugin> plugins) {this.plugins = plugins;}public PaymentPlugin getPlugin(String payType) {return plugins.stream().filter(plugin -> plugin.support(payType)).findFirst().orElseThrow(() -> new IllegalArgumentException("Unsupported payment type: " + payType));}public List<String> getSupportedPayments() {return plugins.stream().map(PaymentPlugin::getName).collect(Collectors.toList());}
}

4. 配置文件设置

plugins:payment:alipay: truewechat: truepaypal: false

5. 在服务中使用

@Service
public class PaymentService {private final PaymentPluginManager pluginManager;@Autowiredpublic PaymentService(PaymentPluginManager pluginManager) {this.pluginManager = pluginManager;}public PaymentResult processPayment(String payType, PaymentRequest request) {PaymentPlugin plugin = pluginManager.getPlugin(payType);return plugin.pay(request);}public List<String> getSupportedPaymentMethods() {return pluginManager.getSupportedPayments();}
}

优缺点分析

优点:

  • • 实现简单,无需额外的框架支持

  • • 与Spring生态完全兼容

  • • 启动时即完成插件加载,性能稳定

缺点:

  • • 不支持运行时动态加载/卸载插件

  • • 所有插件代码都需要在编译时确定

  • • 插件之间可能存在依赖冲突

适用场景

  • • 功能模块相对稳定,变化不频繁的系统

  • • 简单的SaaS多租户系统中不同租户的功能定制

  • • 不同部署环境需要不同功能模块的场景

  • 关注公众号:码猿技术专栏,回复关键词:1111 获取阿里内部Java性能调优手册!

方案二:基于SPI机制实现

原理介绍

SPI(Service Provider Interface)是Java提供的一种服务发现机制,允许第三方为系统提供实现。SpringBoot也提供了类似机制的扩展,可以利用它实现一种松耦合的插件化架构。

实现步骤

  1. 1. 定义插件接口和抽象类

  2. 2. 实现SPI配置

  3. 3. 创建插件实现类

  4. 4. 实现插件加载器

代码示例

1. 定义插件接口

public interface ReportPlugin {String getType();boolean support(String reportType);byte[] generateReport(ReportRequest request);
}

2. 创建SPI配置文件

META-INF/services/目录下创建与接口全限定名同名的文件,如:
META-INF/services/com.example.plugin.ReportPlugin

文件内容为实现类的全限定名:

com.example.plugin.impl.PdfReportPlugin
com.example.plugin.impl.ExcelReportPlugin
com.example.plugin.impl.HtmlReportPlugin

3. 实现插件类

public class PdfReportPlugin implements ReportPlugin {@Overridepublic String getType() {return "pdf";}@Overridepublic boolean support(String reportType) {return "pdf".equals(reportType);}@Overridepublic byte[] generateReport(ReportRequest request) {System.out.println("Generating PDF report");// PDF生成逻辑return "PDF Report Content".getBytes();}
}// 其他插件实现类类似

4. 插件加载器

@Component
public class SpiPluginLoader {private static final Logger logger = LoggerFactory.getLogger(SpiPluginLoader.class);private final Map<String, ReportPlugin> reportPlugins = new HashMap<>();@PostConstructpublic void loadPlugins() {ServiceLoader<ReportPlugin> serviceLoader = ServiceLoader.load(ReportPlugin.class);for (ReportPlugin plugin : serviceLoader) {logger.info("Loading report plugin: {}", plugin.getType());reportPlugins.put(plugin.getType(), plugin);}logger.info("Loaded {} report plugins", reportPlugins.size());}public ReportPlugin getReportPlugin(String type) {ReportPlugin plugin = reportPlugins.get(type);if (plugin == null) {throw new IllegalArgumentException("Unsupported report type: " + type);}return plugin;}public List<String> getSupportedReportTypes() {return new ArrayList<>(reportPlugins.keySet());}
}

5. 在服务中使用

@Service
public class ReportService {private final SpiPluginLoader pluginLoader;@Autowiredpublic ReportService(SpiPluginLoader pluginLoader) {this.pluginLoader = pluginLoader;}public byte[] generateReport(String reportType, ReportRequest request) {ReportPlugin plugin = pluginLoader.getReportPlugin(reportType);return plugin.generateReport(request);}public List<String> getSupportedReportTypes() {return pluginLoader.getSupportedReportTypes();}
}

优缺点分析

优点:

  • • 标准的Java SPI机制,无需引入额外依赖

  • • 插件实现与主程序解耦,便于第三方扩展

  • • 配置简单,只需添加配置文件

缺点:

  • • 不支持运行时动态加载/卸载插件

  • • 无法控制插件加载顺序

适用场景

  • • 需要支持第三方扩展的开源框架

  • • 系统中的通用功能需要多种实现的场景

  • • 插件之间无复杂依赖关系的系统

方案三:基于SpringBoot自动配置实现

原理介绍

SpringBoot的自动配置机制是实现插件化的另一种强大方式。通过创建独立的starter模块,每个插件可以自包含所有依赖和配置,实现"即插即用"。

实现步骤

  1. 1. 创建核心模块定义插件接口

  2. 2. 为每个插件创建独立的starter

  3. 3. 实现自动配置类

  4. 4. 在主应用中集成插件

代码示例

1. 核心模块接口定义

// plugin-core模块
public interface StoragePlugin {String getType();boolean support(String storageType);String store(byte[] data, String path);byte[] retrieve(String path);
}

2. 插件实现模块

// local-storage-plugin模块
public class LocalStoragePlugin implements StoragePlugin {private final String rootPath;public LocalStoragePlugin(String rootPath) {this.rootPath = rootPath;}@Overridepublic String getType() {return "local";}@Overridepublic boolean support(String storageType) {return "local".equals(storageType);}@Overridepublic String store(byte[] data, String path) {// 本地存储实现String fullPath = rootPath + "/" + path;System.out.println("Storing data to: " + fullPath);// 实际存储逻辑return fullPath;}@Overridepublic byte[] retrieve(String path) {// 本地读取实现System.out.println("Retrieving data from: " + path);// 实际读取逻辑return "Local file content".getBytes();}
}

3. 自动配置类

@Configuration
@ConditionalOnProperty(prefix = "storage", name = "type", havingValue = "local")
@EnableConfigurationProperties(LocalStorageProperties.class)
public class LocalStorageAutoConfiguration {@Bean@ConditionalOnMissingBeanpublic StoragePlugin localStoragePlugin(LocalStorageProperties properties) {return new LocalStoragePlugin(properties.getRootPath());}
}@ConfigurationProperties(prefix = "storage.local")
public class LocalStorageProperties {private String rootPath = "/tmp/storage";// getter and setterpublic String getRootPath() {return rootPath;}public void setRootPath(String rootPath) {this.rootPath = rootPath;}
}

4. spring.factories配置

META-INF/spring.factories文件中添加:

org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
com.example.storage.local.LocalStorageAutoConfiguration

5. 类似地实现其他存储插件

// s3-storage-plugin模块
public class S3StoragePlugin implements StoragePlugin {// 实现亚马逊S3存储...
}@Configuration
@ConditionalOnProperty(prefix = "storage", name = "type", havingValue = "s3")
@EnableConfigurationProperties(S3StorageProperties.class)
public class S3StorageAutoConfiguration {@Bean@ConditionalOnMissingBeanpublic StoragePlugin s3StoragePlugin(S3StorageProperties properties) {return new S3StoragePlugin(properties.getAccessKey(), properties.getSecretKey(), properties.getBucket());}
}

6. 主应用使用插件

@Service
public class FileService {private final StoragePlugin storagePlugin;@Autowiredpublic FileService(StoragePlugin storagePlugin) {this.storagePlugin = storagePlugin;}public String saveFile(byte[] data, String path) {return storagePlugin.store(data, path);}public byte[] getFile(String path) {return storagePlugin.retrieve(path);}
}

7. 配置文件设置

storage:type: local  # 可选值: local, s3, oss等local:root-path: /data/files

优缺点分析

优点:

  • • 符合SpringBoot规范,易于集成

  • • 插件可以包含完整的依赖和配置

  • • 可通过配置动态切换插件

  • • 插件可以访问Spring上下文

缺点:

  • • 需要重启应用才能更换插件

  • • 所有可能的插件需要预先定义

  • • 多个插件同时存在可能引起依赖冲突

适用场景

  • • 企业级应用中需要支持多种技术实现的场景

  • • 不同部署环境使用不同技术栈的情况

  • • 需要将复杂功能模块化的大型应用

方案四:动态加载JAR实现

原理介绍

这种方案实现了真正的运行时动态加载插件,通过自定义ClassLoader加载外部JAR文件,实现插件的热插拔。

实现步骤

  1. 1. 设计插件接口和扩展点

  2. 2. 实现插件加载器

  3. 3. 创建插件管理服务

  4. 4. 实现插件生命周期管理

代码示例

1. 核心接口定义

// 插件接口
public interface Plugin {String getId();String getName();String getVersion();void initialize(PluginContext context);void start();void stop();
}// 插件上下文
public interface PluginContext {ApplicationContext getApplicationContext();ClassLoader getClassLoader();File getPluginDirectory();
}

2. 自定义类加载器

public class PluginClassLoader extends URLClassLoader {private final File pluginJarFile;public PluginClassLoader(File pluginJarFile, ClassLoader parent) throws MalformedURLException {super(new URL[]{pluginJarFile.toURI().toURL()}, parent);this.pluginJarFile = pluginJarFile;}public File getPluginJarFile() {return pluginJarFile;}
}

3. 插件加载器

@Component
public class JarPluginLoader {private static final Logger logger = LoggerFactory.getLogger(JarPluginLoader.class);@Value("${plugins.directory:/plugins}")private String pluginsDirectory;@Autowiredprivate ApplicationContext applicationContext;public Plugin loadPlugin(File jarFile) throws Exception {logger.info("Loading plugin from: {}", jarFile.getAbsolutePath());PluginClassLoader classLoader = new PluginClassLoader(jarFile, getClass().getClassLoader());// 查找plugin.properties文件URL pluginPropertiesUrl = classLoader.findResource("plugin.properties");if (pluginPropertiesUrl == null) {throw new IllegalArgumentException("Missing plugin.properties in plugin JAR");}Properties pluginProperties = new Properties();try (InputStream is = pluginPropertiesUrl.openStream()) {pluginProperties.load(is);}String mainClass = pluginProperties.getProperty("plugin.main-class");if (mainClass == null) {throw new IllegalArgumentException("Missing plugin.main-class in plugin.properties");}// 加载并实例化插件主类Class<?> pluginClass = classLoader.loadClass(mainClass);if (!Plugin.class.isAssignableFrom(pluginClass)) {throw new IllegalArgumentException("Plugin main class must implement Plugin interface");}Plugin plugin = (Plugin) pluginClass.getDeclaredConstructor().newInstance();// 创建插件上下文PluginContext context = new DefaultPluginContext(applicationContext, classLoader, new File(pluginsDirectory, plugin.getId()));// 初始化插件plugin.initialize(context);return plugin;}// 简单的插件上下文实现private static class DefaultPluginContext implements PluginContext {private final ApplicationContext applicationContext;private final ClassLoader classLoader;private final File pluginDirectory;public DefaultPluginContext(ApplicationContext applicationContext, ClassLoader classLoader, File pluginDirectory) {this.applicationContext = applicationContext;this.classLoader = classLoader;this.pluginDirectory = pluginDirectory;if (!pluginDirectory.exists()) {pluginDirectory.mkdirs();}}@Overridepublic ApplicationContext getApplicationContext() {return applicationContext;}@Overridepublic ClassLoader getClassLoader() {return classLoader;}@Overridepublic File getPluginDirectory() {return pluginDirectory;}}
}

4. 插件管理服务

@Service
public class PluginManagerService {private static final Logger logger = LoggerFactory.getLogger(PluginManagerService.class);@Value("${plugins.directory:/plugins}")private String pluginsDirectory;@Autowiredprivate JarPluginLoader pluginLoader;private final Map<String, Plugin> loadedPlugins = new ConcurrentHashMap<>();private final Map<String, PluginClassLoader> pluginClassLoaders = new ConcurrentHashMap<>();@PostConstructpublic void init() {loadAllPlugins();}public void loadAllPlugins() {File directory = new File(pluginsDirectory);if (!directory.exists() || !directory.isDirectory()) {directory.mkdirs();return;}File[] jarFiles = directory.listFiles((dir, name) -> name.endsWith(".jar"));if (jarFiles != null) {for (File jarFile : jarFiles) {try {loadPlugin(jarFile);} catch (Exception e) {logger.error("Failed to load plugin: {}", jarFile.getName(), e);}}}}public Plugin loadPlugin(File jarFile) throws Exception {Plugin plugin = pluginLoader.loadPlugin(jarFile);String pluginId = plugin.getId();// 如果插件已加载,先停止并卸载if (loadedPlugins.containsKey(pluginId)) {unloadPlugin(pluginId);}// 启动插件plugin.start();// 保存插件和类加载器loadedPlugins.put(pluginId, plugin);pluginClassLoaders.put(pluginId, (PluginClassLoader) plugin.getClass().getClassLoader());logger.info("Plugin loaded and started: {}", plugin.getName());return plugin;}public void unloadPlugin(String pluginId) {Plugin plugin = loadedPlugins.get(pluginId);if (plugin != null) {try {plugin.stop();logger.info("Plugin stopped: {}", plugin.getName());} catch (Exception e) {logger.error("Error stopping plugin: {}", plugin.getName(), e);}loadedPlugins.remove(pluginId);// 清理类加载器PluginClassLoader classLoader = pluginClassLoaders.remove(pluginId);if (classLoader != null) {try {classLoader.close();} catch (IOException e) {logger.error("Error closing plugin class loader", e);}}}}public List<PluginInfo> getLoadedPlugins() {return loadedPlugins.values().stream().map(plugin -> new PluginInfo(plugin.getId(), plugin.getName(), plugin.getVersion())).collect(Collectors.toList());}@Data@AllArgsConstructorpublic static class PluginInfo {private String id;private String name;private String version;}
}

5. 插件控制器

@RestController
@RequestMapping("/api/plugins")
public class PluginController {@Autowiredprivate PluginManagerService pluginManager;@GetMappingpublic List<PluginManagerService.PluginInfo> getPlugins() {return pluginManager.getLoadedPlugins();}@PostMapping("/upload")public ResponseEntity<String> uploadPlugin(@RequestParam("file") MultipartFile file) {if (file.isEmpty() || !file.getOriginalFilename().endsWith(".jar")) {return ResponseEntity.badRequest().body("Please upload a valid JAR file");}try {// 保存上传的JAR文件File tempFile = File.createTempFile("plugin-", ".jar");file.transferTo(tempFile);// 加载插件Plugin plugin = pluginManager.loadPlugin(tempFile);return ResponseEntity.ok("Plugin uploaded and loaded: " + plugin.getName());} catch (Exception e) {return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to load plugin: " + e.getMessage());}}@DeleteMapping("/{pluginId}")public ResponseEntity<String> unloadPlugin(@PathVariable String pluginId) {try {pluginManager.unloadPlugin(pluginId);return ResponseEntity.ok("Plugin unloaded: " + pluginId);} catch (Exception e) {return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to unload plugin: " + e.getMessage());}}@PostMapping("/reload")public ResponseEntity<String> reloadAllPlugins() {try {pluginManager.loadAllPlugins();return ResponseEntity.ok("All plugins reloaded");} catch (Exception e) {return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body("Failed to reload plugins: " + e.getMessage());}}
}

6. 插件示例实现

// 在独立项目中开发插件
public class ReportGeneratorPlugin implements Plugin {private PluginContext context;private boolean running = false;@Overridepublic String getId() {return "report-generator";}@Overridepublic String getName() {return "Report Generator Plugin";}@Overridepublic String getVersion() {return "1.0.0";}@Overridepublic void initialize(PluginContext context) {this.context = context;}@Overridepublic void start() {running = true;System.out.println("Report Generator Plugin started");// 注册REST接口或服务try {ApplicationContext appContext = context.getApplicationContext();// 这里需要特殊处理来注册新的Controller} catch (Exception e) {e.printStackTrace();}}@Overridepublic void stop() {running = false;System.out.println("Report Generator Plugin stopped");}// 插件特定功能public byte[] generateReport(String type, Map<String, Object> data) {// 报表生成逻辑return "Report Content".getBytes();}
}

7. 插件描述文件 (plugin.properties)

plugin.id=report-generator
plugin.name=Report Generator Plugin
plugin.version=1.0.0
plugin.main-class=com.example.plugin.report.ReportGeneratorPlugin
plugin.author=Your Name
plugin.description=A plugin for generating various types of reports

优缺点分析

优点:

  • • 支持真正的运行时动态加载/卸载插件

  • • 插件可以完全独立开发和部署

  • • 主应用无需重启即可更新插件

缺点:

  • • 实现复杂,需要处理类加载器和资源隔离问题

  • • 可能存在内存泄漏风险

  • • 插件与主应用的通信需要精心设计

  • • 版本兼容性问题难以处理

适用场景

  • • 需要在运行时动态更新功能的系统

  • • 第三方开发者需要扩展的平台

  • • 插件开发和主应用开发由不同团队负责的情况

  • • 微内核架构的应用系统

方案对比

特性

条件注解

SPI机制

自动配置

动态JAR

实现复杂度

运行时加载

资源隔离

Spring集成

很好

一般

很好

一般

开发门槛

部署复杂度

适合规模

小型

小型

中型

中大型

总结

插件化架构不仅是一种技术选择,更是一种系统设计思想。

通过将系统分解为核心框架和可插拔组件,我们能够构建更加灵活、可维护和可扩展的应用系统,更好地应对不断变化的业务需求。

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

如若内容造成侵权/违法违规/事实不符,请联系英文站点网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

VGG-19(Visual Geometry Group)模型

VGG-19 是由牛津大学视觉几何组和 Google DeepMind 的研究人员在 2014 年提出的一个非常经典的深度卷积神经网络模型。 一 核心结构 &#xff08;1&#xff09;深度&#xff1a; 模型名称中的 "19" 指的是模型拥有 19 层带有权重的层&#xff08;通常指&#xff1a;…

Windows11 鼠标卡死任务栏卡死 假死解决方法

最近很多朋友都有一个问题&#xff0c;就是Windows11电脑 在编辑文档或者是切换窗口的时候出现任务栏假死&#xff0c;鼠标左右键失灵等现象&#xff0c;想了几天解决方案今天吧最直接的方法教给大家 首发玖毅论坛 玖毅论坛https://www.webbbs.cn/ 第一步&#xff1a; 第一种…

BeikeShop - 一个开源、用户友好的跨境电子商务平台

BeikeShop - 一个开源、用户友好的跨境电子商务平台 BeikeShop 是全球领先的基于 Laravel 框架的开源电子商务平台&#xff0c;专为国际贸易和跨境电子商务行业设计。 该系统是 100% 开源的&#xff01;它支持多语言、多币种、支付、物流、会员管理等广泛的实用功能&#xff0…

基于大模型的胆囊结石全周期诊疗方案研究报告

目录 一、引言 1.1 研究背景与意义 1.2 研究目的与目标 1.3 研究方法与创新点 二、大模型预测胆囊结石的原理与技术基础 2.1 大模型概述 2.2 用于胆囊结石预测的数据来源 2.3 模型构建与训练 2.4 模型评估指标 三、术前风险预测与手术方案制定 3.1 术前评估指标与数…

[论文阅读] 人工智能 | Gen-n-Val:利用代理技术革新计算机视觉数据生成

Gen-n-Val&#xff1a;利用代理技术革新计算机视觉数据生成 论文信息 article{huang2025gennval,title{Gen-n-Val: Agentic Image Data Generation and Validation},author{Huang, Jing-En and Fang, I-Sheng and Huang, Tzuhsuan and Wang, Chih-Yu and Chen, Jun-Cheng},jo…

【AI论文】ReasonMed:一个370K的多智能体生成数据集,用于推进医疗推理

摘要&#xff1a;尽管基于推理的大型语言模型&#xff08;LLM&#xff09;在数学和编程方面表现出色&#xff0c;但它们在知识密集型医疗问题回答方面的能力仍未得到充分探索。为解决这一问题&#xff0c;我们推出了ReasonMed&#xff0c;这是最大的医疗推理数据集&#xff0c;…

singlefligt使用方法和源码解读

singlefligt使用方法和源码解读 介绍 sync.once保证其整个生命周期内只调用一次&#xff1b;而singleflight则可以保证在一定范围内其只调用一次。 背景|使用场景 应对缓存击穿&#xff1a;加锁可以解决这个问题&#xff0c;但是加锁不太灵活&#xff08;不能控制访问频率之…

HTTP 协议的基本概念(请求/响应流程、状态码、Header、方法)问题解决方案大全

HTTP 协议的基本概念&#xff08;请求/响应流程、状态码、Header、方法&#xff09;问题解决方案大全 一. 摘要 HTTP 协议是 Web 开发的基石&#xff0c;但初学者往往只停留在 GET、POST 的层面&#xff0c;对重定向机制、缓存控制、请求体解析等概念缺乏深入理解&#xff0c;…

Python中常用的函数

以下是Python中常用的函数分类整理&#xff0c;涵盖基础操作、数据处理、文件操作、面向对象等场景&#xff0c;并附上示例说明&#xff1a; --- ### **一、基础内置函数** | 函数 | 作用 | 示例 | |----…

【Windows】删除鼠标右键多余菜单的方法

要删除鼠标右键菜单中的多余菜单&#xff0c;如&#xff1a;“打开抖音壁纸”选项&#xff0c;通常需要通过修改注册表或使用第三方工具来清理残留的注册表项。以下是详细步骤&#xff08;操作注册表前务必备份&#xff01;&#xff09;&#xff1a; 方法一&#xff1a;通过注册…

【性能优化】启用zram

性能优化 系统内存不足时&#xff0c;可以考虑启动ZRAM功能&#xff08;压缩内存&#xff09;。关于ZRAM的概念&#xff0c;可自行学习。这里记录一下&#xff0c;启用ZRAM的方式。 启用ZRAM&#xff0c;可能会导致CPU升高&#xff0c;以及低内存时的恶性循环。是否启用需要综…

深度解析YOLOv8:CSPHet卷积结构如何实现极致轻量化

文章目录 一、背景介绍1.1 YOLOv8的现状1.2 降参数的必要性 二、相关技术介绍2.1 Dual思想2.2 HetConv 三、CSPHet结构设计3.1 CSP模块的改进3.2 结合HetConv3.3 参数量的下降 四、CSPHet的代码实现五、实验结果六、总结与展望 在目标检测领域&#xff0c;YOLO系列算法一直以其…

适配器模式demo

#include <QCoreApplication> #include <iostream>using namespace std;class XmCom { public:void ComByXm(){cout << "XM电源适配器只适用于小米笔记本电脑" << endl;} };class LxCom { public:virtual void ComByLx() 0;virtual ~LxCom…

数据处理考核要求-SQL测试的答案

在一个团队中&#xff0c;有业务人员。如业务人员深入理解数据处理的内容&#xff0c;会大幅度增强相互配合的效率。 针对业务人员进行针对性培训&#xff0c;还是比较容易掌握SQL的数据处理。类似与大学里面开的一门选修课。数据集选择帆软的Demo数据集。 业务人员学会SQL的…

第十七届全国大学生数学竞赛(数学类)初赛模拟试题

上周组委会发布了第十七届全国大学生数学竞赛通知&#xff0c;初赛暂定于2025年11月8日(星期六)上午9:00-11:30举行&#xff0c;同时今年新增了个亮点&#xff0c;针对与数学类的同学&#xff0c;即&#xff1a; 为提升全国大学生数学竞赛的含金量和公平性&#xff0c;并进一步…

解决: React Native iOS webview 空白页

iOS react-native-webview 之前是正常的, 升级了 react-native / react-native-webview 等 之后, 就变成了空白页. 通过下面的修改, 可以修复, 回到正常的状态. 来源: https://github.com/react-native-webview/react-native-webview/issues/3697 diff --git a/node_modules/…

VMware安装Ubuntu并实现root远程登录

前置信息 垃圾Ubuntu系统默认ssh、vim都没有&#xff01;&#xff01;&#xff01; 已踩坑cnmUbuntu处于sb安全机制要求&#xff0c;默认是禁用root直接登录的 1、修改root密码 sudo -sH &#xff08;可以让一个具有sudo权限的普通用户进入 root&#xff09; 然后就是pas…

量化面试绿皮书:20. 正态生成

文中内容仅限技术学习与代码实践参考&#xff0c;市场存在不确定性&#xff0c;技术分析需谨慎验证&#xff0c;不构成任何投资建议。 20. 正态生成 Q: 如何生成两个标准正态分布&#xff08;N(0,1)&#xff09;的随机变量&#xff0c;使它们之间的相关系数为p&#xff0c;假设…

Arduino入门教程:10、屏幕显示

飞书文档https://x509p6c8to.feishu.cn/docx/N45Pd0tA1oaC4CxUWZjc8Ekyn0b 屏幕应用场景 课程使用的SSD1306是一款128*64像素可以使用IIC驱动的OLED屏幕。 SSD1306 Oled显示模块共有4个引脚&#xff0c;标记为GND, VCC, SCL和SDA。这种Oled显示模块可以使用3.3V到5V轻松上电。…

华为云Flexus+DeepSeek征文|体验华为云ModelArts快速搭建Dify-LLM应用开发平台并创建自己dify钉钉群聊机器人

华为云FlexusDeepSeek征文&#xff5c;体验华为云ModelArts快速搭建Dify-LLM应用开发平台并创建自己dify钉钉群聊机器人 什么是华为云ModelArts 华为云ModelArts ModelArts是华为云提供的全流程AI开发平台&#xff0c;覆盖从数据准备到模型部署的全生命周期管理&#xff0c;帮…