WangHan
2024-09-12 d5855a4926926698b740bc6c7ba489de47adb68b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package tech.powerjob.server.config;
 
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
 
import javax.websocket.server.ServerEndpointConfig;
 
/**
 * WebSocket 配置
 * 解决 SpringBoot WebSocket 无法注入对象(@Resource/@Autowired)的问题
 *
 * @author tjq
 * @since 2020/5/17
 */
@Component
public class OmsEndpointConfigure extends ServerEndpointConfig.Configurator implements ApplicationContextAware {
 
    private static volatile ApplicationContext context;
 
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        context = applicationContext;
    }
 
    @Override
    public <T> T getEndpointInstance(Class<T> clazz) throws InstantiationException {
        return context.getBean(clazz);
    }
}