RuoYi/ruoyi-admin/src/main/java/com/ruoyi/web/config/WebSocketConfig.java

41 lines
1.2 KiB
Java
Raw Normal View History

2025-09-22 17:27:11 +08:00
package com.ruoyi.web.config;
2025-09-23 18:46:32 +08:00
import com.ruoyi.customer.service.ICustomerServiceService;
import com.ruoyi.web.websocket.CustomerServiceWebSocket;
import org.springframework.beans.factory.annotation.Autowired;
2025-09-22 17:27:11 +08:00
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
2025-09-23 18:46:32 +08:00
import org.springframework.context.annotation.Bean;
import javax.annotation.PostConstruct;
2025-09-22 17:27:11 +08:00
/**
2025-09-23 18:46:32 +08:00
* WebSocket配置类
* 用于注入服务到WebSocket端点
2025-09-22 17:27:11 +08:00
*
* @author ruoyi
2025-09-23 18:46:32 +08:00
* @date 2024-01-01
2025-09-22 17:27:11 +08:00
*/
@Configuration
public class WebSocketConfig {
2025-09-23 18:46:32 +08:00
@Autowired
private ICustomerServiceService customerServiceService;
2025-09-22 17:27:11 +08:00
/**
2025-09-23 18:46:32 +08:00
* 注入ServerEndpointExporter这个bean会自动注册使用了@ServerEndpoint注解声明的Websocket endpoint
2025-09-22 17:27:11 +08:00
*/
@Bean
public ServerEndpointExporter serverEndpointExporter() {
return new ServerEndpointExporter();
}
2025-09-23 18:46:32 +08:00
/**
* 初始化时将服务注入到WebSocket中
*/
@PostConstruct
public void init() {
CustomerServiceWebSocket customerServiceWebSocket = new CustomerServiceWebSocket();
customerServiceWebSocket.setCustomerServiceService(customerServiceService);
}
2025-09-22 17:27:11 +08:00
}