当前位置: 首页 > news >正文

yml配置动态数据源(数据库@DS)与引起(If you want an embedded database (H2, HSQL or Derby))类问题

1:yml 配置

spring:datasource:dynamic:datasource:master:url: jdbc:mysql://192.168.11.50:3306/dsdd?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=UTCusername: rootpassword: rootdriver-class-name: com.mysql.cj.jdbc.Driversecond-datasource:url: jdbc:mysql://192.168.11.50:3306/commons_utils?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=UTCusername: rootpassword: rootdriver-class-name: com.mysql.cj.jdbc.Driver

2:必须pom依赖配

        <!-- 动态数据源 --><dependency><groupId>com.baomidou</groupId><artifactId>dynamic-datasource-spring-boot-starter</artifactId><version>3.2.0</version></dependency>

2-1:不要加入一下依赖不然会报以下错误

        <dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId><version>1.4.200</version><scope>runtime</scope></dependency><!-- druid --><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.2.6</version></dependency>

在这里插入图片描述

2-2:当出现以上错误可以在yml配置文件去掉DruidDataSourceAutoConfigure,如下

spring:autoconfigure:exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure

3:加入数据库连接池druid依赖管理(使用多数据源一定要用链接池),Druid是阿里巴巴开源的一个数据库连接池和实时数据分析组件。相比其他连接池,Druid在功能特性、性能、监控等方面有很多优势,比如支持SQL解析、慢SQL日志、提供多维度监控等

spring:autoconfigure:exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfiguredatasource:druid:stat-view-servlet:enabled: trueloginUsername: adminloginPassword: 123456allow:web-stat-filter:enabled: truedynamic:druid: # 全局druid参数,绝大部分值和默认保持一致。(现已支持的参数如下,不清楚含义不要乱设置)# 连接池的配置信息# 初始化大小,最小,最大initial-size: 5min-idle: 5maxActive: 20# 配置获取连接等待超时的时间rmaxWait: 60000# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒timeBetweenEvictionRunsMillis: 60000# 配置一个连接在池中最小生存的时间,单位是毫秒minEvictableIdleTimeMillis: 300000validationQuery: SELECT 1 FROM DUALtestWhileIdle: truetestOnBorrow: falsetestOnReturn: false# 打开PSCache,并且指定每个连接上PSCache的大小poolPreparedStatements: truemaxPoolPreparedStatementPerConnectionSize: 20# 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙filters: stat,wall,slf4j# 通过connectProperties属性来打开mergeSql功能;慢SQL记录connectionProperties: druid.stat.mergeSql\=true;druid.stat.slowSqlMillis\=5000datasource:master:url: jdbc:mysql://192.168.11.50:3306/dsdd?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=UTCusername: rootpassword: rootdriver-class-name: com.mysql.cj.jdbc.Driversecond:url: jdbc:mysql://192.168.11.50:3306/commons_utils?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=UTCusername: rootpassword: rootdriver-class-name: com.mysql.cj.jdbc.Driver

3-1:加入依赖

        <!-- 动态数据源 --><dependency><groupId>com.baomidou</groupId><artifactId>dynamic-datasource-spring-boot-starter</artifactId><version>3.2.0</version></dependency><!-- druid --><dependency><groupId>com.alibaba</groupId><artifactId>druid-spring-boot-starter</artifactId><version>1.2.6</version></dependency>

Druid连接池的自动配置类是DruidDataSourceAutoConfigure类上有一行注解

@EnableConfigurationProperties({DruidStatProperties.class, DataSourceProperties.class})

@EnableConfigurationProperties注解的作用是:使配置文件中的配置生效并且映射到指定类的属性

DruidStatProperties:指定的前缀是spring.datasource.druid,主要设置连接池的一些参数

DataSourceProperties:指定的前缀是spring.datasource,主要设置url,username,password等信息

3-2:DruidConfig 配置类

package com.example.poi.config;import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
import com.alibaba.druid.spring.boot.autoconfigure.properties.DruidStatProperties;
import com.alibaba.druid.util.Utils;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;import javax.servlet.*;
import java.io.IOException;/*** @Description: DruidConfig配置类*/
@Configuration
@AutoConfigureAfter(DruidDataSourceAutoConfigure.class)
public class DruidConfig {/*** 带有广告的common.js全路径,druid-1.1.14*/private static final String FILE_PATH = "support/http/resources/js/common.js";/*** 原始脚本,触发构建广告的语句*/private static final String ORIGIN_JS = "this.buildFooter();";/*** 替换后的脚本*/private static final String NEW_JS = "//this.buildFooter();";/*** 去除Druid监控页面的广告** @param properties DruidStatProperties属性集合* @return {@link FilterRegistrationBean}*/@Bean@ConditionalOnWebApplication@ConditionalOnProperty(name = "spring.datasource.druid.stat-view-servlet.enabled", havingValue = "true")public FilterRegistrationBean<RemoveAdFilter> removeDruidAdFilter(DruidStatProperties properties) throws IOException {// 获取web监控页面的参数DruidStatProperties.StatViewServlet config = properties.getStatViewServlet();// 提取common.js的配置路径String pattern = config.getUrlPattern() != null ? config.getUrlPattern() : "/druid/*";String commonJsPattern = pattern.replaceAll("\\*", "js/common.js");// 获取common.jsString text = Utils.readFromResource(FILE_PATH);// 屏蔽 this.buildFooter(); 不构建广告final String newJs = text.replace(ORIGIN_JS, NEW_JS);FilterRegistrationBean<RemoveAdFilter> registration = new FilterRegistrationBean<>();registration.setFilter(new RemoveAdFilter(newJs));registration.addUrlPatterns(commonJsPattern);return registration;}/*** 删除druid的广告过滤器** @author BBF*/private class RemoveAdFilter implements Filter {private final String newJs;public RemoveAdFilter(String newJs) {this.newJs = newJs;}@Overridepublic void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)throws IOException, ServletException {chain.doFilter(request, response);// 重置缓冲区,响应头不会被重置response.resetBuffer();response.getWriter().write(newJs);}}
}

4:配置动态数据源方法二,yml随意配置或者通过配置类生成数据库链接

4-1:yml配置(记得配置数据库链接池)

datasource:master:url: jdbc:mysql://192.168.11.50:3306/dsdd?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=UTCusername: rootpassword: rootdriver-class-name: com.mysql.cj.jdbc.Driversecond:url: jdbc:mysql://192.168.11.50:3306/commons_utils?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=UTCusername: rootpassword: rootdriver-class-name: com.mysql.cj.jdbc.Driver

4-2:配置动态源数据类

@Configuration
public class DatabaseConfig {@Value("${datasource.master.url}")private String dataSourceUrl;@Value("${datasource.master.username}")private String dataSourceUsername;@Value("${datasource.master.password}")private String dataSourcePassword;@Value("${datasource.master.driver-class-name}")private String dataSourceDriverClassName;@Value("${datasource.second.url}")private String dataSourceUrl2;@Value("${datasource.second.username}")private String dataSourceUsername2;@Value("${datasource.second.password}")private String dataSourcePassword2;@Value("${datasource.second.driver-class-name}")private String dataSourceDriverClassName2;public DataSource dataSource() {return  DataSourceBuilder.create().url(dataSourceUrl).username(dataSourceUsername).password(dataSourcePassword).driverClassName("com.mysql.cj.jdbc.Driver").build();}public DataSource dataSource2() {return DataSourceBuilder.create().url(dataSourceUrl2).username(dataSourceUsername2).password(dataSourcePassword2).driverClassName("com.mysql.cj.jdbc.Driver").build();}// 添加动态数据源@Beanpublic DynamicRoutingDataSource dynamicDataSource() {DynamicRoutingDataSource dynamicRoutingDataSource = new DynamicRoutingDataSource();dynamicRoutingDataSource.addDataSource("master", dataSource());dynamicRoutingDataSource.addDataSource("two", dataSource2());return dynamicRoutingDataSource;}
}

4-3:在server服务层通过@DS调用

    @Override@DS("two")public List<EntityDemo> testSql(Page<EntityDemo> pageList, String id)  {List<EntityDemo> entityDemos = entityDemoMapper.testSql(pageList, id);DynamicDataSourceContextHolder.clear();return entityDemos;

4-4:可以在启动类观察动态数据源情况如下:run.getBean(DataSource.class).getConnection();

@SpringBootApplication
@MapperScan(basePackages = "com.example.poi.mapper")
public class PoiApplication {public static void main(String[] args) {ConfigurableApplicationContext run = SpringApplication.run(PoiApplication.class, args);// 检查数据库连接是否正常try {// 获取DataSource bean,并调用getConnection()方法测试连接run.getBean(javax.sql.DataSource.class).getConnection();System.out.println("数据库连接正常!");} catch (Exception e) {System.err.println("数据库连接异常:" + e.getMessage());// 处理连接异常的逻辑}}
}

在这里插入图片描述

5:方法三配置动态数据源使,使用注解的方式(推荐使用)

5-1:yml配置

spring:datasource:master:jdbcUrl: jdbc:mysql://192.168.11.50:3306/dsdd?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=UTCusername: rootpassword: rootdriver-class-name: com.mysql.cj.jdbc.Driversecond:jdbcUrl: jdbc:mysql://192.168.11.50:3306/commons_utils?characterEncoding=UTF-8&useUnicode=true&useSSL=false&tinyInt1isBit=false&allowPublicKeyRetrieval=true&serverTimezone=UTCusername: rootpassword: rootdriverClassName: com.mysql.cj.jdbc.Driverdruid:#连接池初始化时创建的数据库连接数量initial-size: 10#连接池中保持最小的空闲连接数量。如果空闲连接数量少于这个值,连接池会创建新的连接来补充min-idle: 5#max-active: 80#配置获取链接等待超时的时间max-wait:type: com.alibaba.druid.pool.DruidDataSource

5-2:配置动态源数据类(在需要切换的地方使用@DS就可以),整合mybatis-plus的过程中,我们还需要创建动态数据源的SqlSessionFactory,如果我们想要实现动态数据源切换,则需要手动配置SqlSessionFactory,以便于它使用动态数据源,同理事务管理器也需要重新配置:

@Configuration
public class DatabaseConfig {@Bean("one")@ConfigurationProperties(prefix = "spring.datasource.master")public DataSource dataSource() {return DataSourceBuilder.create().build();}@Bean("two")@ConfigurationProperties(prefix = "spring.datasource.second")public DataSource dataSource2() {return DataSourceBuilder.create().build();}//添加动态数据源@Beanpublic DynamicRoutingDataSource dynamicDataSource(@Qualifier("one") DataSource dataSource, @Qualifier("two") DataSource dataSource2) {DynamicRoutingDataSource dynamicRoutingDataSource = new DynamicRoutingDataSource();dynamicRoutingDataSource.addDataSource("master", dataSource);dynamicRoutingDataSource.addDataSource("two", dataSource2);return dynamicRoutingDataSource;}@Bean("sqlSessionFactory")public SqlSessionFactory sqlSessionFactoryBean(DynamicRoutingDataSource dynamicRoutingDataSource) throws Exception {//使用SqlSessionFactoryBean不可以正常使用 BaseMapper的MyBatis通用的CRUD//SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();MybatisSqlSessionFactoryBean sessionFactory = new MybatisSqlSessionFactoryBean();sessionFactory.setDataSource(dynamicRoutingDataSource);return sqlSessionFactoryBean.getObject();}/*** 重写事务管理器,管理动态数据源*/@Primary@Bean(value = "transactionManager")public PlatformTransactionManager annotationDrivenTransactionManager(DynamicRoutingDataSource dataSource) {return new DataSourceTransactionManager(dataSource);}
}

5-3:切换使用数据源

在这里插入图片描述

6:方法四配置动态数据源使用,使用注解的方式(推荐使用)

6-1:添加注解和切面

package com.example.poi.minds.annotation;import java.lang.annotation.*;/*** @Author xu* @create 2023/9/7 22*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface MinDS {/*** groupName or specific database name or spring SPEL name.** @return the database you want to switch*/String value() default "";
}
package com.example.poi.minds.aop;import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.example.poi.config.DataSourceHolder;
import com.example.poi.desensitization.annotation.SensitiveDecode;
import com.example.poi.desensitization.annotation.SensitiveEncode;
import com.example.poi.desensitization.utils.SensitiveInfoUtil;
import com.example.poi.minds.annotation.MinDS;
import lombok.extern.slf4j.Slf4j;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.lang.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;import java.lang.reflect.Method;
import java.util.List;/*** @Author xu* @create 2023/9/7 22*/
@Slf4j
@Aspect
@Component
public class MinDSAspect {/*** 定义切点Pointcut*/@Pointcut("@annotation(com.example.poi.minds.annotation.MinDS) ")public void dsPointCut() {}@Around("dsPointCut()")public Object around(ProceedingJoinPoint joinPoint) throws Throwable {// 处理结果MethodSignature signature = (MethodSignature) joinPoint.getSignature();Method method = signature.getMethod();MinDS minDS = method.getAnnotation(MinDS.class);String value = minDS.value();if (StringUtils.isBlank(value)) {return null;}DataSourceHolder.setDataSource(value);try {return joinPoint.proceed();} finally {DataSourceHolder.clearDataSource();}}
}

在这里插入图片描述

6-2:动态数据源简单的说就是能够自由切换的数据源,Spring提供了一个抽象类AbstractRoutingDataSource,我们只需要extends ,并且重写determineCurrentLookupKey()即可determineCurrentLookupKey()的作用:返回需要切换的数据源的key,然后根据这个key获取对应的数据源信息

package com.example.poi.config;import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;/*** @Author xu* @create 2023/9/7 22*/
public class DynamicDataSource extends AbstractRoutingDataSource {/*** 返回需要使用的数据源key,将会按照这个key从Map中获取对应的数据源(切换)* @return*/@Overrideprotected Object determineCurrentLookupKey() {//从ThreadLocal中取出keyreturn DataSourceHolder.getDataSource();}}

6-3:单独封装一个类:DataSourceHolder,在多线程的情况下,数据源切换如何保证线程隔离呢?,我们不能这边切换了影响了其他线程的执行,这里我们便想到了ThreadLocal

package com.example.poi.config;/*** @Author xu* @create 2023/9/7 20*/
/*** 线程安全类:使用ThreadLocal存储切换数据源后的KEY*/
public class DataSourceHolder {/*** 线程ThreadLocal*/private static final ThreadLocal<String> dataSources = new InheritableThreadLocal();/*** 设置数据源* @param datasource*/public static void setDataSource(String datasource) {dataSources.set(datasource);}/*** 获取数据源* @return*/public static String getDataSource() {return dataSources.get();}/*** 清除数据源*/public static void clearDataSource() {dataSources.remove();}}

相关文章:

yml配置动态数据源(数据库@DS)与引起(If you want an embedded database (H2, HSQL or Derby))类问题

1&#xff1a;yml 配置 spring:datasource:dynamic:datasource:master:url: jdbc:mysql://192.168.11.50:3306/dsdd?characterEncodingUTF-8&useUnicodetrue&useSSLfalse&tinyInt1isBitfalse&allowPublicKeyRetrievaltrue&serverTimezoneUTCusername: ro…...

yolov5运行过程遇到的小问题(随时更新)

1.关于git的问题 解决办法&#xff1a;插入下面代码 import os os.environ["GIT_PYTHON_REFRESH"] "quiet"2.页面太小无法完成操作 解决办法: 如果不好使再考虑降低Batch_Size大小或者调整虚拟内存可用硬盘空间大小&#xff01;&#xff08;调整虚拟内存…...

使用FabricJS创建Image对象的JSON表示

本篇文章介绍一下如何创建图像的 JSON 表示形式 使用 FabricJS 的对象。我们可以通过创建一个实例来创建一个 Image 对象 织物.图像。由于它是FabricJS的基本元素之一&#xff0c;我们也可以轻松地 通过应用角度、不透明度等属性来自定义它。为了创建 JSON Image 对象的表示&am…...

【牛客刷题】反转固定区间链表、每k个节点一组反转

链表内指定区间反转_牛客题霸_牛客网 ListNode* reverseList(ListNode* head, ListNode* tail) {ListNode* pre nullptr;ListNode* cur head;while (cur ! tail) { 最后cur就是tailListNode* temp cur->next;cur->next pre;pre cur;cur temp;}return pre;}ListNode…...

算法:数组常见套路1---双指针、取模、打擂台法

文章来源&#xff1a; https://blog.csdn.net/weixin_45630258/article/details/132738318 欢迎各位大佬指点、三连 一、数组的合并–双指针[快慢指针] 1、题目&#xff1a; 给你两个按 非递减顺序 排列的整数数组 nums1 和 nums2&#xff0c;另有两个整数 m 和 n &#xff0…...

App 出海实践:Google Play 结算系统

作者&#xff1a;业志陈 现如今&#xff0c;App 出海热度不减&#xff0c;是很多公司和个人开发者选择的一个市场方向。App 为了实现盈利&#xff0c;除了接入广告这种最常见的变现方式外&#xff0c;就是通过提供各类虚拟商品或者是会员服务来吸引用户付费了&#xff0c;此时 …...

国际慈善日 | 追寻大爱无疆,拓世科技集团的公益之路

每年的9月5日&#xff0c;是联合国大会正式选定的国际慈善日。这一天的设立&#xff0c;旨在通过提高公众对慈善活动的意识&#xff0c;鼓励慈善公益活动通过各种形式在全球范围内得到增强和发展。这是一个向慈善公益事业致敬的日子&#xff0c;同时也是呼吁全球团结一致共同发…...

关于DNS的一些认识

目录 什么是DNS&#xff1f; 一台具有单个DNS的机器可以拥有多个地址吗&#xff1f; 一台计算机可以有多个属于不同顶级域的DNS名字吗&#xff1f; 什么是DNS&#xff1f; DNS是域名系统&#xff08;Domain Name System&#xff09;的缩写&#xff0c;它是互联网中用于将域名…...

游戏性能优化

Unity性能优化主要包括以下方面&#xff1a; 1.渲染性能 。包括减少Draw Calls、减少三角面数、使用LOD、使用批处理技术、减少实时光源等&#xff0c;以提高游戏的帧率和渲染效率。 2.内存性能 。包括使用对象池、使用合适的纹理、使用异步加载资源等&#xff0c;以减少内存占…...

公开游戏、基于有向图的游戏

目录 〇&#xff0c;背景 一&#xff0c;公开游戏、策梅洛定理 1&#xff0c;公开游戏 2&#xff0c;策梅洛定理 二&#xff0c;有向图游戏 1&#xff0c;狭义有向图游戏 2&#xff0c;广义有向图游戏 3&#xff0c;狭义有向图游戏的SG数 4&#xff0c;Bash Game 力扣…...

CSS学习笔记05

CSS笔记05 定位 position CSS 属性position - 用于指定一个元素在文档中的定位方式。top&#xff0c;right&#xff0c;bottom 和 left 属性则决定了该元素的最终位置。position 有以下常用的属性值&#xff1a; position: static; - 默认值。指定元素使用正常的布局行为&am…...

Linux查看指定端口是否被占用

在Linux中&#xff0c;可以使用多种方法来检查一个特定端口&#xff08;例如3306&#xff0c;通常由MySQL使用&#xff09;是否被占用&#xff1a; 使用netstat命令: 如果系统中已安装了netstat&#xff0c;可以使用以下命令检查3306端口&#xff1a; netstat -tuln | grep 330…...

【Python 自动化】小说推文一键生成思路概述

最近看了一下小说推文成品软件的思路&#xff0c;发现可以完全迁移到我的 BookerAutoVideo 上面来。这篇短文里面&#xff0c;我试着分析一下整个推文视频生成的流程&#xff0c;以及简要阐述一下有什么工具。 整体流程是这样&#xff1a; 分句 原文是按照段落组织的&#xf…...

MySQL中的字符集与排序规则详解

在 MySQL 中&#xff0c;字符集&#xff08;Character Set&#xff09;用于确定可以在数据库中存储的字符集合&#xff0c;而排序规则&#xff08;Collation&#xff09;用于指定比较和排序字符串的规则。下面是关于 MySQL 中字符集和排序规则的一些详细信息&#xff1a; 字符集…...

Java中如何进行加锁??

笔者在上篇文章介绍了线程安全的问题&#xff0c;接下来本篇文章就是来讲解如何避免线程安全问题~~ 前言&#xff1a;创建两个线程&#xff0c;每个线程都实现对同一个变量count各自自增5W次&#xff0c;我们来看一下代码&#xff1a; class Counter{private int count0;publi…...

Pytorch3D多角度渲染.obj模型

3D理解在从自动驾驶汽车和自主机器人到虚拟现实和增强现实的众多应用中发挥着至关重要的作用。在过去的一年里&#xff0c;PyTorch3D已经成为一个越来越流行的开源框架&#xff0c;用于使用Python进行3D深度学习。值得庆幸的是&#xff0c;PyTorch3D 库背后的人员已经完成了实现…...

MyBatisPlus 基础Mapperr接口:增删改查

MyBatisPlus 基础Mapper接口&#xff1a;增删改查 插入一条数据 代码 Testpublic void insert() {User user new User();user.setId(6L);user.setName("张三");user.setAge(25);user.setEmail("zhangsanexample.com");userMapper.insert(user);}日志 数…...

计算机网络与技术——概述

&#x1f60a;计算机网络与技术——概述 &#x1f47b;前言&#x1f94f;信息时代下计算机网络的发展&#x1f30f;互联网概述&#x1f4e1;计算机网络基本概念&#x1f4e1;互联网发展三阶段&#x1f4e1;互联网的标准化 &#x1f30f;互联网的组成&#x1f4e1;互联网的边缘部…...

详解TCP/IP协议第三篇:通信数据在OSI通信模型的上下传输

文章目录 一:OSI通信模型间数据传输展示 二:应用层到会话层解析 1:应用层 2:表现层 3:会话层...

《C++ primer plus》精炼(OOP部分)——对象和类(2)

“学习是人类成长的喷泉。” - 亚里士多德 文章目录 内联函数对象的方法和属性构造函数和析构函数构造函数的种类使用构造函数析构函数列表初始化 const成员函数this指针对象数组类作用域作用域为类的常量类作用域内的枚举 内联函数 定义位于类声明中的函数自动成为内联函数。…...

mongodb源码分析session执行handleRequest命令find过程

mongo/transport/service_state_machine.cpp已经分析startSession创建ASIOSession过程&#xff0c;并且验证connection是否超过限制ASIOSession和connection是循环接受客户端命令&#xff0c;把数据流转换成Message&#xff0c;状态转变流程是&#xff1a;State::Created 》 St…...

如何在看板中体现优先级变化

在看板中有效体现优先级变化的关键措施包括&#xff1a;采用颜色或标签标识优先级、设置任务排序规则、使用独立的优先级列或泳道、结合自动化规则同步优先级变化、建立定期的优先级审查流程。其中&#xff0c;设置任务排序规则尤其重要&#xff0c;因为它让看板视觉上直观地体…...

JVM垃圾回收机制全解析

Java虚拟机&#xff08;JVM&#xff09;中的垃圾收集器&#xff08;Garbage Collector&#xff0c;简称GC&#xff09;是用于自动管理内存的机制。它负责识别和清除不再被程序使用的对象&#xff0c;从而释放内存空间&#xff0c;避免内存泄漏和内存溢出等问题。垃圾收集器在Ja…...

五年级数学知识边界总结思考-下册

目录 一、背景二、过程1.观察物体小学五年级下册“观察物体”知识点详解&#xff1a;由来、作用与意义**一、知识点核心内容****二、知识点的由来&#xff1a;从生活实践到数学抽象****三、知识的作用&#xff1a;解决实际问题的工具****四、学习的意义&#xff1a;培养核心素养…...

RabbitMQ入门4.1.0版本(基于java、SpringBoot操作)

RabbitMQ 一、RabbitMQ概述 RabbitMQ RabbitMQ最初由LShift和CohesiveFT于2007年开发&#xff0c;后来由Pivotal Software Inc.&#xff08;现为VMware子公司&#xff09;接管。RabbitMQ 是一个开源的消息代理和队列服务器&#xff0c;用 Erlang 语言编写。广泛应用于各种分布…...

【从零开始学习JVM | 第四篇】类加载器和双亲委派机制(高频面试题)

前言&#xff1a; 双亲委派机制对于面试这块来说非常重要&#xff0c;在实际开发中也是经常遇见需要打破双亲委派的需求&#xff0c;今天我们一起来探索一下什么是双亲委派机制&#xff0c;在此之前我们先介绍一下类的加载器。 目录 ​编辑 前言&#xff1a; 类加载器 1. …...

认识CMake并使用CMake构建自己的第一个项目

1.CMake的作用和优势 跨平台支持&#xff1a;CMake支持多种操作系统和编译器&#xff0c;使用同一份构建配置可以在不同的环境中使用 简化配置&#xff1a;通过CMakeLists.txt文件&#xff0c;用户可以定义项目结构、依赖项、编译选项等&#xff0c;无需手动编写复杂的构建脚本…...

Linux中《基础IO》详细介绍

目录 理解"文件"狭义理解广义理解文件操作的归类认知系统角度文件类别 回顾C文件接口打开文件写文件读文件稍作修改&#xff0c;实现简单cat命令 输出信息到显示器&#xff0c;你有哪些方法stdin & stdout & stderr打开文件的方式 系统⽂件I/O⼀种传递标志位…...

Vue3 PC端 UI组件库我更推荐Naive UI

一、Vue3生态现状与UI库选择的重要性 随着Vue3的稳定发布和Composition API的广泛采用&#xff0c;前端开发者面临着UI组件库的重新选择。一个好的UI库不仅能提升开发效率&#xff0c;还能确保项目的长期可维护性。本文将对比三大主流Vue3 UI库&#xff08;Naive UI、Element …...

【iOS】 Block再学习

iOS Block再学习 文章目录 iOS Block再学习前言Block的三种类型__ NSGlobalBlock____ NSMallocBlock____ NSStackBlock__小结 Block底层分析Block的结构捕获自由变量捕获全局(静态)变量捕获静态变量__block修饰符forwarding指针 Block的copy时机block作为函数返回值将block赋给…...