41 lines
1.2 KiB
Java
41 lines
1.2 KiB
Java
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);
|
||
}
|
||
} |