当前位置: 首页 > 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;以思路一为例进行调…...

「DataX」数据迁移-IDEA运行DataX方法总结

背景 业务需求希望把Oracle数据库中的数据&#xff0c;迁移至MySql数据库中&#xff0c;因为需要迁移全量和增量的数据&#xff0c;所以希望想用数据迁移工具进行操作。 经过一些调研查询&#xff0c;最终打算使用DataX进行数据的迁移。 DataX简单介绍 DataX 是阿里云 DataW…...

【 <一> 炼丹初探:JavaWeb 的起源与基础】之 Servlet 过滤器:实现请求的预处理与后处理

<前文回顾> 点击此处查看 合集 https://blog.csdn.net/foyodesigner/category_12907601.html?fromshareblogcolumn&sharetypeblogcolumn&sharerId12907601&sharereferPC&sharesourceFoyoDesigner&sharefromfrom_link <今日更新> 一、过滤器&…...

DeepSeek与浏览器自动化AI Agent构建指南

文章使用到的模型可以用硅基流动中的&#xff1a; 注册链接&#xff1a;硅基流动统一登录 邀请码&#xff1a;FytHp9Xa 一、技术选型阶段 1. 基础组件选择 AI模型&#xff1a;DeepSeek-R1开放API&#xff08;对话/推理&#xff09;或DeepSeek-Coder&#xff08;代码生成&#…...

面试中常问的mysql数据库指令【杭州多测师_王sir】

数据库中的修改表结构、增删改查、用户权限操作DDL 》数据库定义语言 create database&#xff0c;create table drop tableDML 》数据库操作语言 insert into&#xff0c;delete from&#xff0c;update set&#xff0c;DQL 》数据库查询语言 select .... from....crea…...

深度学习驱动的智能化革命:从技术突破到行业实践

第一章 深度学习的技术演进与核心架构 1.1 从浅层网络到深度学习的范式转变 深度学习的核心在于通过多层次非线性变换自动提取数据特征,其发展历程可划分为三个阶段:符号主义时代的规则驱动(1950s-1980s)、连接主义时代的浅层网络(1990s-2000s)以及深度学习时代的端到端…...

基于编译器特性浅析C++程序性能优化

最近在恶补计算机基础知识&#xff0c;学到CSAPP第五章的内容&#xff0c;在这里总结并且展开一下C程序性能优化相关的内容。 衡量程序性能的方式 一般而言&#xff0c;程序的性能可以用CPE&#xff08;Cycles Per Element&#xff09;来衡量&#xff0c;其指的是处理每个元素…...

服务器上通过ollama部署deepseek

2025年1月下旬&#xff0c;DeepSeek的R1模型发布后的一周内就火了&#xff0c;性能比肩OpenAI的o1模型&#xff0c;且训练成本仅为560万美元&#xff0c;成本远低于openAI&#xff0c;使得英伟达股票大跌。 下面我们来看下如何个人如何部署deepseek-r1模型。 我是用的仙宫云的…...

Android Coil总结

文章目录 Android Coil总结概述添加依赖用法基本用法占位图变形自定义ImageLoader取消加载协程支持缓存清除缓存监听 简单封装 Android Coil总结 概述 Coil 是一个用于 Android 的 Kotlin 图像加载库&#xff0c;旨在简化图像加载和显示的过程。它基于 Kotlin 协程&#xff0…...

《安富莱嵌入式周报》第351期:DIY半导体制造,工业设备抗干扰提升方法,NASA软件开发规范,小型LCD在线UI编辑器,开源USB PD电源,开源锂电池管理

周报汇总地址&#xff1a;嵌入式周报 - uCOS & uCGUI & emWin & embOS & TouchGFX & ThreadX - 硬汉嵌入式论坛 - Powered by Discuz! 视频版&#xff1a; https://www.bilibili.com/video/BV16C95YEEZs 《安富莱嵌入式周报》第351期&#xff1a;DIY半导体…...

Redis在人员管理系统中的应用示例

用户会话管理 场景&#xff1a;用户登录后存储会话信息&#xff0c;支持多服务器共享 实现&#xff1a; 用户登录成功后&#xff0c;生成唯一Token&#xff08;如JWT&#xff09;&#xff0c;作为Redis的Key Value存储用户ID、角色、权限等信息&#xff0c;设置过期时间&…...