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

使用websocket,注入依赖service的bean为null

问题:依赖注入失败,service获取不到,提示null

这是参考代码

package com.shier.ws;import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.google.gson.Gson;
import com.shier.config.HttpSessionConfig;
import com.shier.model.domain.Chat;
import com.shier.model.domain.Team;
import com.shier.model.domain.User;
import com.shier.model.request.MessageRequest;
import com.shier.model.vo.ChatMessageVO;
import com.shier.model.vo.WebSocketVO;
import com.shier.service.ChatService;
import com.shier.service.TeamService;
import com.shier.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.io.Serializable;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArraySet;import static com.shier.constants.ChatConstant.*;
import static com.shier.constants.UserConstants.ADMIN_ROLE;
import static com.shier.constants.UserConstants.USER_LOGIN_STATE;/*** WebSocket服务*/
@Component
@Slf4j
@ServerEndpoint(value = "/websocket/{userId}/{teamId}", configurator = HttpSessionConfig.class)
public class WebSocket {/*** 保存队伍的连接信息*/private static final Map<String, ConcurrentHashMap<String, WebSocket>> ROOMS = new HashMap<>();/*** 线程安全的无序的集合*/private static final CopyOnWriteArraySet<Session> SESSIONS = new CopyOnWriteArraySet<>();/*** 会话池*/private static final Map<String, Session> SESSION_POOL = new HashMap<>(0);/*** 用户服务*/private static UserService userService;/*** 聊天服务*/private static ChatService chatService;/*** 团队服务*/private static TeamService teamService;/*** 房间在线人数*/private static int onlineCount = 0;/*** 当前信息*/private Session session;/*** http会话*/private HttpSession httpSession;/*** 上网数** @return int*/public static synchronized int getOnlineCount() {return onlineCount;}/*** 添加在线计数*/public static synchronized void addOnlineCount() {WebSocket.onlineCount++;}/*** 子在线计数*/public static synchronized void subOnlineCount() {WebSocket.onlineCount--;}/*** 集热地图服务** @param userService 用户服务*/@Resourcepublic void setHeatMapService(UserService userService) {WebSocket.userService = userService;}/*** 集热地图服务** @param chatService 聊天服务*/@Resourcepublic void setHeatMapService(ChatService chatService) {WebSocket.chatService = chatService;}/*** 集热地图服务** @param teamService 团队服务*/@Resourcepublic void setHeatMapService(TeamService teamService) {WebSocket.teamService = teamService;}/*** 队伍内群发消息** @param teamId 团队id* @param msg    消息*/public static void broadcast(String teamId, String msg) {ConcurrentHashMap<String, WebSocket> map = ROOMS.get(teamId);// keySet获取map集合key的集合  然后在遍历key即可for (String key : map.keySet()) {try {WebSocket webSocket = map.get(key);webSocket.sendMessage(msg);} catch (Exception e) {e.printStackTrace();}}}/*** 发送消息** @param message 消息* @throws IOException ioexception*/public void sendMessage(String message) throws IOException {this.session.getBasicRemote().sendText(message);}/*** 开放** @param session 会话* @param userId  用户id* @param teamId  团队id* @param config  配置*/@OnOpenpublic void onOpen(Session session, @PathParam(value = "userId") String userId, @PathParam(value = "teamId") String teamId, EndpointConfig config) {try {if (StringUtils.isBlank(userId) || "undefined".equals(userId)) {sendError(userId, "参数有误");return;}HttpSession httpSession = (HttpSession) config.getUserProperties().get(HttpSession.class.getName());User user = (User) httpSession.getAttribute(USER_LOGIN_STATE);if (user != null) {this.session = session;this.httpSession = httpSession;}if (!"NaN".equals(teamId)) {if (!ROOMS.containsKey(teamId)) {ConcurrentHashMap<String, WebSocket> room = new ConcurrentHashMap<>(0);room.put(userId, this);ROOMS.put(String.valueOf(teamId), room);// 在线数加1addOnlineCount();} else {if (!ROOMS.get(teamId).containsKey(userId)) {ROOMS.get(teamId).put(userId, this);// 在线数加1addOnlineCount();}}} else {SESSIONS.add(session);SESSION_POOL.put(userId, session);sendAllUsers();}} catch (Exception e) {e.printStackTrace();}}/*** 关闭** @param userId  用户id* @param teamId  团队id* @param session 会话*/@OnClosepublic void onClose(@PathParam("userId") String userId, @PathParam(value = "teamId") String teamId, Session session) {try {if (!"NaN".equals(teamId)) {ROOMS.get(teamId).remove(userId);if (getOnlineCount() > 0) {subOnlineCount();}} else {if (!SESSION_POOL.isEmpty()) {SESSION_POOL.remove(userId);SESSIONS.remove(session);}sendAllUsers();}} catch (Exception e) {e.printStackTrace();}}/*** 消息** @param message 消息* @param userId  用户id*/@OnMessagepublic void onMessage(String message, @PathParam("userId") String userId) {if ("PING".equals(message)) {sendOneMessage(userId, "pong");return;}MessageRequest messageRequest = new Gson().fromJson(message, MessageRequest.class);Long toId = messageRequest.getToId();Long teamId = messageRequest.getTeamId();String text = messageRequest.getText();Integer chatType = messageRequest.getChatType();User fromUser = userService.getById(userId);Team team = teamService.getById(teamId);if (chatType == PRIVATE_CHAT) {// 私聊privateChat(fromUser, toId, text, chatType);} else if (chatType == TEAM_CHAT) {// 队伍内聊天teamChat(fromUser, text, team, chatType);} else {// 群聊hallChat(fromUser, text, chatType);}}/*** 队伍聊天** @param user     用户* @param text     文本* @param team     团队* @param chatType 聊天类型*/private void teamChat(User user, String text, Team team, Integer chatType) {ChatMessageVO ChatMessageVO = new ChatMessageVO();WebSocketVO fromWebSocketVO = new WebSocketVO();BeanUtils.copyProperties(user, fromWebSocketVO);ChatMessageVO.setFormUser(fromWebSocketVO);ChatMessageVO.setText(text);ChatMessageVO.setTeamId(team.getId());ChatMessageVO.setChatType(chatType);ChatMessageVO.setCreateTime(DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));if (user.getId() == team.getUserId() || user.getRole() == ADMIN_ROLE) {ChatMessageVO.setIsAdmin(true);}User loginUser = (User) this.httpSession.getAttribute(USER_LOGIN_STATE);if (loginUser.getId() == user.getId()) {ChatMessageVO.setIsMy(true);}String toJson = new Gson().toJson(ChatMessageVO);try {broadcast(String.valueOf(team.getId()), toJson);saveChat(user.getId(), null, text, team.getId(), chatType);chatService.deleteKey(CACHE_CHAT_TEAM, String.valueOf(team.getId()));} catch (Exception e) {throw new RuntimeException(e);}}/*** 大厅聊天** @param user     用户* @param text     文本* @param chatType 聊天类型*/private void hallChat(User user, String text, Integer chatType) {ChatMessageVO ChatMessageVO = new ChatMessageVO();WebSocketVO fromWebSocketVO = new WebSocketVO();BeanUtils.copyProperties(user, fromWebSocketVO);ChatMessageVO.setFormUser(fromWebSocketVO);ChatMessageVO.setText(text);ChatMessageVO.setChatType(chatType);ChatMessageVO.setCreateTime(DateUtil.format(new Date(), "yyyy年MM月dd日 HH:mm:ss"));if (user.getRole() == ADMIN_ROLE) {ChatMessageVO.setIsAdmin(true);}User loginUser = (User) this.httpSession.getAttribute(USER_LOGIN_STATE);if (loginUser.getId() == user.getId()) {ChatMessageVO.setIsMy(true);}String toJson = new Gson().toJson(ChatMessageVO);sendAllMessage(toJson);saveChat(user.getId(), null, text, null, chatType);chatService.deleteKey(CACHE_CHAT_HALL, String.valueOf(user.getId()));}/*** 私聊** @param user     用户* @param toId     为id* @param text     文本* @param chatType 聊天类型*/private void privateChat(User user, Long toId, String text, Integer chatType) {ChatMessageVO ChatMessageVO = chatService.chatResult(user.getId(), toId, text, chatType, DateUtil.date(System.currentTimeMillis()));User loginUser = (User) this.httpSession.getAttribute(USER_LOGIN_STATE);if (loginUser.getId() == user.getId()) {ChatMessageVO.setIsMy(true);}String toJson = new Gson().toJson(ChatMessageVO);sendOneMessage(toId.toString(), toJson);saveChat(user.getId(), toId, text, null, chatType);chatService.deleteKey(CACHE_CHAT_PRIVATE, user.getId() + "" + toId);chatService.deleteKey(CACHE_CHAT_PRIVATE, toId + "" + user.getId());}/*** 保存聊天** @param userId   用户id* @param toId     为id* @param text     文本* @param teamId   团队id* @param chatType 聊天类型*/private void saveChat(Long userId, Long toId, String text, Long teamId, Integer chatType) {
//        if (chatType == PRIVATE_CHAT) {
//            User user = userService.getById(userId);
//            Set<Long> userIds = stringJsonListToLongSet(user.getFriendIds());
//            if (!userIds.contains(toId)) {
//                sendError(String.valueOf(userId), "该用户不是你的好友");
//                return;
//            }
//        }Chat chat = new Chat();chat.setFromId(userId);chat.setText(String.valueOf(text));chat.setChatType(chatType);chat.setCreateTime(new Date());if (toId != null && toId > 0) {chat.setToId(toId);}if (teamId != null && teamId > 0) {chat.setTeamId(teamId);}chatService.save(chat);}/*** 发送失败** @param userId       用户id* @param errorMessage 错误消息*/private void sendError(String userId, String errorMessage) {JSONObject obj = new JSONObject();obj.set("error", errorMessage);sendOneMessage(userId, obj.toString());}/*** 广播消息** @param message 消息*/public void sendAllMessage(String message) {for (Session session : SESSIONS) {try {if (session.isOpen()) {synchronized (session) {session.getBasicRemote().sendText(message);}}} catch (Exception e) {e.printStackTrace();}}}/*** 发送一个消息** @param userId  用户编号* @param message 消息*/public void sendOneMessage(String userId, String message) {Session session = SESSION_POOL.get(userId);if (session != null && session.isOpen()) {try {synchronized (session) {session.getBasicRemote().sendText(message);}} catch (Exception e) {e.printStackTrace();}}}/*** 给所有用户*/public void sendAllUsers() {HashMap<String, List<WebSocketVO>> stringListHashMap = new HashMap<>(0);List<WebSocketVO> WebSocketVOs = new ArrayList<>();stringListHashMap.put("users", WebSocketVOs);for (Serializable key : SESSION_POOL.keySet()) {User user = userService.getById(key);WebSocketVO WebSocketVO = new WebSocketVO();BeanUtils.copyProperties(user, WebSocketVO);WebSocketVOs.add(WebSocketVO);}sendAllMessage(JSONUtil.toJsonStr(stringListHashMap));}
}

这是自己的代码

package com.ruoyi.webSocket;import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.room.domain.Room;
import com.ruoyi.room.service.IRoomService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;@Component
@ServerEndpoint("/module/websocket/{userId}/{roomId}")
public class WebSocketServer implements ApplicationContextAware {private static IRoomService roomService;private static final Logger log = LoggerFactory.getLogger(WebSocketServer.class);// 保存队伍的连接信息 - 新增private static final Map<String, ConcurrentHashMap<String, WebSocketServer>> ROOMS = new HashMap<>();//静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。private static AtomicInteger onlineNum = new AtomicInteger();//concurrent包的线程安全Set,用来存放每个客户端对应的WebSocketServer对象。private static ConcurrentHashMap<String, Session> sessionPools = new ConcurrentHashMap<>();// 线程安全list,用来存放 在线客户端账号public static List<String> userList = new CopyOnWriteArrayList<>();// 连接成功@OnOpenpublic void onOpen(Session session, @PathParam(value = "userId") String userId, @PathParam(value = "roomId") String roomId) {// 创建session给客户sessionPools.put(userId, session);if (!userList.contains(userId)) {addOnlineCount();userList.add(userId);}try {if (StringUtils.isBlank(userId) || "undefined".equals(userId) ||StringUtils.isBlank(roomId) || "undefined".equals(roomId)) {sendError(userId, "参数有误");return;}if (!ROOMS.containsKey(roomId)) {// 房间不存在 创建房间ConcurrentHashMap<String, WebSocketServer> room = new ConcurrentHashMap<>(0);room.put(userId, this);ROOMS.put(String.valueOf(roomId), room);} else {if (!ROOMS.get(roomId).containsKey(userId)) {// 房间存在 客户不存在 房间加入客户ROOMS.get(roomId).put(userId, this);}}log.debug("ID为【" + userId + "】的用户加入websocket!当前在线人数为:" + onlineNum);log.debug("当前在线:" + userList);} catch (Exception e) {e.printStackTrace();}}/*** 关闭连接* @param userId*/@OnClosepublic void onClose(@PathParam(value = "userId") String userId) {sessionPools.remove(userId);if (userList.contains(userId)) {userList.remove(userId);subOnlineCount();}log.debug(userId + "断开webSocket连接!当前人数为" + onlineNum);}/*** 消息监听 接收客户端消息* @param message* @throws IOException*/@OnMessagepublic void onMessage(String message) throws IOException {JSONObject jsonObject = JSONObject.parseObject(message);String userId = jsonObject.getString("userId");String roomId = jsonObject.getString("roomId");String type = jsonObject.getString("type");if (type.equals(MessageType.DETAIL.getType())) {log.debug("房间详情");try {Room room = roomService.selectRoomById(Long.parseLong(roomId));jsonObject.put("roomInfo", room);ConcurrentHashMap<String, WebSocketServer> map = ROOMS.get(roomId);// 获取玩家列表 keySet获取map集合key的集合  然后在遍历key即可for (String key : map.keySet()) {try {sendToUser(key, JSONObject.toJSONString(jsonObject));} catch (Exception e) {e.printStackTrace();}}} catch (NumberFormatException e) {System.out.println("转换错误: " + e.getMessage());}}}/*** 连接错误* @param session* @param throwable* @throws IOException*/@OnErrorpublic void onError(Session session, Throwable throwable) throws IOException {log.error("websocket连接错误!");throwable.printStackTrace();}/*** 发送消息*/public void sendMessage(Session session, String message) throws IOException, EncodeException {if (session != null) {synchronized (session) {session.getBasicRemote().sendText(message);}}}/*** 给指定用户发送信息*/public void sendToUser(String userId, String message) {Session session = sessionPools.get(userId);try {if (session != null) {sendMessage(session, message);}else {log.debug("推送用户不在线");}} catch (Exception e) {e.printStackTrace();}}public static void addOnlineCount() {onlineNum.incrementAndGet();}public static void subOnlineCount() {onlineNum.decrementAndGet();}/*** 发送失败** @param userId       用户id* @param errorMessage 错误消息*/private void sendError(String userId, String errorMessage) {JSONObject obj = new JSONObject();obj.put("error", errorMessage);sendOneMessage(userId, obj.toString());}/*** 发送一个消息** @param userId  用户编号* @param message 消息*/public void sendOneMessage(String userId, String message) {Session session = sessionPools.get(userId);if (session != null && session.isOpen()) {try {synchronized (session) {session.getBasicRemote().sendText(message);}} catch (Exception e) {e.printStackTrace();}}}
}

修改后的代码

package com.ruoyi.webSocket;import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.room.domain.Room;
import com.ruoyi.room.service.IRoomService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;@Component
@ServerEndpoint("/module/websocket/{userId}/{roomId}")
public class WebSocketServer implements ApplicationContextAware {private static ApplicationContext context;@Overridepublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException {context = applicationContext;}public static <roomService> roomService getBean(Class<roomService> beanClass) {return context.getBean(beanClass);}private static final Logger log = LoggerFactory.getLogger(WebSocketServer.class);// 保存队伍的连接信息 - 新增private static final Map<String, ConcurrentHashMap<String, WebSocketServer>> ROOMS = new HashMap<>();//静态变量,用来记录当前在线连接数。应该把它设计成线程安全的。private static AtomicInteger onlineNum = new AtomicInteger();//concurrent包的线程安全Set,用来存放每个客户端对应的WebSocketServer对象。private static ConcurrentHashMap<String, Session> sessionPools = new ConcurrentHashMap<>();// 线程安全list,用来存放 在线客户端账号public static List<String> userList = new CopyOnWriteArrayList<>();// 连接成功@OnOpenpublic void onOpen(Session session, @PathParam(value = "userId") String userId, @PathParam(value = "roomId") String roomId) {// 创建session给客户sessionPools.put(userId, session);if (!userList.contains(userId)) {addOnlineCount();userList.add(userId);}try {if (StringUtils.isBlank(userId) || "undefined".equals(userId) ||StringUtils.isBlank(roomId) || "undefined".equals(roomId)) {sendError(userId, "参数有误");return;}if (!ROOMS.containsKey(roomId)) {// 房间不存在 创建房间ConcurrentHashMap<String, WebSocketServer> room = new ConcurrentHashMap<>(0);room.put(userId, this);ROOMS.put(String.valueOf(roomId), room);} else {if (!ROOMS.get(roomId).containsKey(userId)) {// 房间存在 客户不存在 房间加入客户ROOMS.get(roomId).put(userId, this);}}log.debug("ID为【" + userId + "】的用户加入websocket!当前在线人数为:" + onlineNum);log.debug("当前在线:" + userList);} catch (Exception e) {e.printStackTrace();}}/*** 关闭连接* @param userId*/@OnClosepublic void onClose(@PathParam(value = "userId") String userId) {sessionPools.remove(userId);if (userList.contains(userId)) {userList.remove(userId);subOnlineCount();}log.debug(userId + "断开webSocket连接!当前人数为" + onlineNum);}/*** 消息监听 接收客户端消息* @param message* @throws IOException*/@OnMessagepublic void onMessage(String message) throws IOException {JSONObject jsonObject = JSONObject.parseObject(message);String userId = jsonObject.getString("userId");String roomId = jsonObject.getString("roomId");String type = jsonObject.getString("type");if (type.equals(MessageType.DETAIL.getType())) {log.debug("房间详情");try {Room room = context.getBean(IRoomService.class).selectRoomById(Long.parseLong(roomId));jsonObject.put("roomInfo", room);ConcurrentHashMap<String, WebSocketServer> map = ROOMS.get(roomId);// 获取玩家列表 keySet获取map集合key的集合  然后在遍历key即可for (String key : map.keySet()) {try {sendToUser(key, JSONObject.toJSONString(jsonObject));} catch (Exception e) {e.printStackTrace();}}} catch (NumberFormatException e) {System.out.println("转换错误: " + e.getMessage());}}}/*** 连接错误* @param session* @param throwable* @throws IOException*/@OnErrorpublic void onError(Session session, Throwable throwable) throws IOException {log.error("websocket连接错误!");throwable.printStackTrace();}/*** 发送消息*/public void sendMessage(Session session, String message) throws IOException, EncodeException {if (session != null) {synchronized (session) {session.getBasicRemote().sendText(message);}}}/*** 给指定用户发送信息*/public void sendToUser(String userId, String message) {Session session = sessionPools.get(userId);try {if (session != null) {sendMessage(session, message);}else {log.debug("推送用户不在线");}} catch (Exception e) {e.printStackTrace();}}public static void addOnlineCount() {onlineNum.incrementAndGet();}public static void subOnlineCount() {onlineNum.decrementAndGet();}/*** 发送失败** @param userId       用户id* @param errorMessage 错误消息*/private void sendError(String userId, String errorMessage) {JSONObject obj = new JSONObject();obj.put("error", errorMessage);sendOneMessage(userId, obj.toString());}/*** 发送一个消息** @param userId  用户编号* @param message 消息*/public void sendOneMessage(String userId, String message) {Session session = sessionPools.get(userId);if (session != null && session.isOpen()) {try {synchronized (session) {session.getBasicRemote().sendText(message);}} catch (Exception e) {e.printStackTrace();}}}
}

核心代码

 private static ApplicationContext context;@Overridepublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException {context = applicationContext;}public static <roomService> roomService getBean(Class<roomService> beanClass) {return context.getBean(beanClass);}
Room room = context.getBean(IRoomService.class).selectRoomById(Long.parseLong(roomId));

原因:执行的先后顺序吧,具体还没仔细了解

相关文章:

使用websocket,注入依赖service的bean为null

问题&#xff1a;依赖注入失败&#xff0c;service获取不到&#xff0c;提示null 这是参考代码 package com.shier.ws;import cn.hutool.core.date.DateUtil; import cn.hutool.json.JSONObject; import cn.hutool.json.JSONUtil; import com.google.gson.Gson; import com.s…...

批量在 Word 的指定位置插入页,如插入封面、末尾插入页面

我们经常会碰到需要在 Word 文档中插入新的页面的需求&#xff0c;比如在 Word 文档末尾插入一个广告页、给 Word 文档插入一个说明封面&#xff0c;在 Word 文档的中间位置插入新的页面等等。相信这个操作对于大部分小伙伴来说都不难&#xff0c;难的是同时给多个 Word 文档插…...

算法系列之滑动窗口

算法系列之滑动窗口 题目 给定一个字符串 s &#xff0c;请你找出其中不含有重复字符的 最长 子串 的长度。 示例 1:输入: s "abcabcbb" 输出: 3 解释: 因为无重复字符的最长子串是 "abc"&#xff0c;所以其长度为 3。 示例 2:输入: s "bbbbb"…...

【C#】详解C#中的内存管理机制

文章目录 前言一、C#内存管理的基本机制&#xff08;1&#xff09;托管堆&#xff08;Managed Heap&#xff09;&#xff08;2&#xff09;垃圾回收&#xff08;Garbage Collection&#xff09;&#xff08;3&#xff09;栈内存 二、 开发者需要主动管理的场景&#xff08;1&am…...

C/S架构与B/S架构

一、定义与核心区别 C/S架构&#xff08;Client/Server&#xff0c;客户端/服务器&#xff09; 客户端需安装专用软件&#xff08;如QQ、企业ERP系统&#xff09;&#xff0c;直接与服务器通信。服务器端通常包括数据库和业务逻辑处理1。特点&#xff1a;客户端承担部分计算任务…...

《DeepSeek MoE架构下,动态专家路由优化全解析》

在人工智能飞速发展的当下&#xff0c;模型架构的创新与优化始终是推动技术进步的关键力量。DeepSeek的混合专家模型&#xff08;MoE&#xff09;架构&#xff0c;以其独特的设计理念和卓越的性能表现&#xff0c;在大模型领域崭露头角。而其中的动态专家路由优化技术&#xff…...

Android双亲委派

下面是一份 Android 类加载器双亲委派机制的时序图示例&#xff0c;描述了当应用调用 loadClass() 时&#xff0c;各个加载器之间的委派过程。 #mermaid-svg-rBdlhpD2uRjBPiG8 {font-family:"trebuchet ms",verdana,arial,sans-serif;font-size:16px;fill:#333;}#mer…...

go语言因为前端跨域导致无法访问到后端解决方案

前端服务8080访问后端8081这端口显示跨域了 ERROR Network Error AxiosError: Network Error at XMLHttpRequest.handleError (webpack-internal:///./node_modules/axios/lib/adapters/xhr.js:116:14) at Axios.request (webpack-internal:///./node_modules/axios/lib/core/A…...

Jmeter使用介绍

文章目录 前言Jmeter简介安装与配置JDK安装与配置JMeter安装与配置 打开JMeter方式一方式二 设置Jmeter语言为中文方法一&#xff08;仅一次性&#xff09;方法二(永久设置成中文) Jmeter文件常用目录 元件与组件元件组件元件的作用域元件的执行顺序第一个案例添加线程组添加 H…...

【商城实战(13)】购物车价格与数量的奥秘

【商城实战】专栏重磅来袭&#xff01;这是一份专为开发者与电商从业者打造的超详细指南。从项目基础搭建&#xff0c;运用 uniapp、Element Plus、SpringBoot 搭建商城框架&#xff0c;到用户、商品、订单等核心模块开发&#xff0c;再到性能优化、安全加固、多端适配&#xf…...

Spring使用@Scheduled注解的参数详解

在现代Java开发中&#xff0c;定时任务是一个常见的需求。Spring框架提供了Scheduled注解&#xff0c;让我们能够以简单、直观的方式定义和管理这些定时任务。接下来&#xff0c;我们来深入探讨这个注解的使用&#xff0c;以及它的参数都有哪些含义和作用。 Scheduled注解可以…...

【网络】HTTP协议、HTTPS协议

HTTP与HTTPS HTTP协议概述 HTTP(超文本传输协议):工作在OSI顶层应用层,用于客户端(浏览器)与服务器之间的通信,B/S模式 无状态:每次请求独立,服务器不保存客户端状态(通过Cookie/Session扩展状态管理)。基于TCP:默认端口80(HTTP)、443(HTTPS),保证可靠传输。请…...

【Windows下Gitbook快速入门使用】

Windows下Gitbook快速入门使用 1 工具安装1.1 Node.js下载安装1.1 环境变量1.2 npm配置1.3 安装gitbook 2 gitbook使用2.1 gitbook 无法执行2.2 gitbook常用命令 Gitbook是一个软件&#xff0c;使用Git和Markdown来编排书本&#xff1b; GitBook helps you pushlish beautiful …...

创建Electron35 + vue3 + electron-builder项目,有很过坑,记录过程

环境&#xff1a; node v20.18.0 npm 11.1.0 用到的所有依赖&#xff1a; "dependencies": {"core-js": "^3.8.3","vue": "^3.2.13","vue-router": "^4.5.0"},"devDependencies": {"ba…...

FPGA 实验报告:四位全加器与三八译码器仿真实现

目录 安装Quartus软件 四位全加器 全加器、半加器 半加器&#xff1a; 全加器&#xff1a; 四位全加器电路图 创建项目 半加器 全加器 四位全加器 代码实现 半加器 全加器 四位全加器 三八译码器 创建项目 代码展示 modelsim仿真波形图 四位全加器 三八译码…...

动态规划详解(二):从暴力递归到动态规划的完整优化之路

目录 一、什么是动态规划&#xff1f;—— 从人类直觉到算法思维 二、暴力递归&#xff1a;最直观的问题分解方式 1. 示例&#xff1a;斐波那契数列 2. 递归树分析&#xff08;以n5为例&#xff09; 3. 问题暴露 三、第一次优化&#xff1a;记忆化搜索&#xff08;Memoiza…...

前端学习——HTML

HTML VSCode常用快捷键HTML标签文本标签列表标签表格Form表单表单元素 块元素与行内元素新增标签 VSCode常用快捷键 代码格式化&#xff1a;ShiftAltF 向上或向下移动一行&#xff1a;AltUp或AltDown 快速复制一行代码&#xff1a;ShiftAltUp或者ShiftAltDown 快速替换&#x…...

12.【线性代数】——图和网络

十二 图和网络&#xff08;线性代数的应用&#xff09; 图 g r a p h { n o d e s , e d g e s } graph\{nodes, edges\} graph{nodes,edges}1.关联矩阵2. A A A矩阵的零空间&#xff0c;求解 A x 0 Ax0 Ax0 电势3. A T A^T AT矩阵的零空间&#xff0c;电流总结电流图结论 …...

[环境搭建篇] Windows 环境下如何安装repo工具

Windows 环境下如何安装repo工具 1. 安装前置依赖2. 配置Repo引导脚本方法一&#xff1a;通过Gitee镜像安装&#xff08;推荐&#xff09;方法二&#xff1a;通过清华镜像安装 3. 解决依赖问题4. 初始化Repo仓库5. 常见问题解决 前言&#xff1a; 在Windows环境下安装Repo工具需…...

LeetCode 热题 100_字符串解码(71_394_中等_C++)(栈)

LeetCode 热题 100_字符串解码&#xff08;71_394&#xff09; 题目描述&#xff1a;输入输出样例&#xff1a;题解&#xff1a;解题思路&#xff1a;思路一&#xff08;栈&#xff09;&#xff1a; 代码实现代码实现&#xff08;栈&#xff09;&#xff1a;以思路一为例进行调…...

Linux应用开发之网络套接字编程(实例篇)

服务端与客户端单连接 服务端代码 #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <arpa/inet.h> #include <pthread.h> …...

云原生核心技术 (7/12): K8s 核心概念白话解读(上):Pod 和 Deployment 究竟是什么?

大家好&#xff0c;欢迎来到《云原生核心技术》系列的第七篇&#xff01; 在上一篇&#xff0c;我们成功地使用 Minikube 或 kind 在自己的电脑上搭建起了一个迷你但功能完备的 Kubernetes 集群。现在&#xff0c;我们就像一个拥有了一块崭新数字土地的农场主&#xff0c;是时…...

HTML 列表、表格、表单

1 列表标签 作用&#xff1a;布局内容排列整齐的区域 列表分类&#xff1a;无序列表、有序列表、定义列表。 例如&#xff1a; 1.1 无序列表 标签&#xff1a;ul 嵌套 li&#xff0c;ul是无序列表&#xff0c;li是列表条目。 注意事项&#xff1a; ul 标签里面只能包裹 li…...

JUC笔记(上)-复习 涉及死锁 volatile synchronized CAS 原子操作

一、上下文切换 即使单核CPU也可以进行多线程执行代码&#xff0c;CPU会给每个线程分配CPU时间片来实现这个机制。时间片非常短&#xff0c;所以CPU会不断地切换线程执行&#xff0c;从而让我们感觉多个线程是同时执行的。时间片一般是十几毫秒(ms)。通过时间片分配算法执行。…...

浅谈不同二分算法的查找情况

二分算法原理比较简单&#xff0c;但是实际的算法模板却有很多&#xff0c;这一切都源于二分查找问题中的复杂情况和二分算法的边界处理&#xff0c;以下是博主对一些二分算法查找的情况分析。 需要说明的是&#xff0c;以下二分算法都是基于有序序列为升序有序的情况&#xf…...

【开发技术】.Net使用FFmpeg视频特定帧上绘制内容

目录 一、目的 二、解决方案 2.1 什么是FFmpeg 2.2 FFmpeg主要功能 2.3 使用Xabe.FFmpeg调用FFmpeg功能 2.4 使用 FFmpeg 的 drawbox 滤镜来绘制 ROI 三、总结 一、目的 当前市场上有很多目标检测智能识别的相关算法&#xff0c;当前调用一个医疗行业的AI识别算法后返回…...

【Go语言基础【12】】指针:声明、取地址、解引用

文章目录 零、概述&#xff1a;指针 vs. 引用&#xff08;类比其他语言&#xff09;一、指针基础概念二、指针声明与初始化三、指针操作符1. &&#xff1a;取地址&#xff08;拿到内存地址&#xff09;2. *&#xff1a;解引用&#xff08;拿到值&#xff09; 四、空指针&am…...

QT3D学习笔记——圆台、圆锥

类名作用Qt3DWindow3D渲染窗口容器QEntity场景中的实体&#xff08;对象或容器&#xff09;QCamera控制观察视角QPointLight点光源QConeMesh圆锥几何网格QTransform控制实体的位置/旋转/缩放QPhongMaterialPhong光照材质&#xff08;定义颜色、反光等&#xff09;QFirstPersonC…...

A2A JS SDK 完整教程:快速入门指南

目录 什么是 A2A JS SDK?A2A JS 安装与设置A2A JS 核心概念创建你的第一个 A2A JS 代理A2A JS 服务端开发A2A JS 客户端使用A2A JS 高级特性A2A JS 最佳实践A2A JS 故障排除 什么是 A2A JS SDK? A2A JS SDK 是一个专为 JavaScript/TypeScript 开发者设计的强大库&#xff…...

【电力电子】基于STM32F103C8T6单片机双极性SPWM逆变(硬件篇)

本项目是基于 STM32F103C8T6 微控制器的 SPWM(正弦脉宽调制)电源模块,能够生成可调频率和幅值的正弦波交流电源输出。该项目适用于逆变器、UPS电源、变频器等应用场景。 供电电源 输入电压采集 上图为本设计的电源电路,图中 D1 为二极管, 其目的是防止正负极电源反接, …...