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

41 lines
1.2 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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