@XxlConf 没生效
wuxinbo opened this issue · 2 comments
wuxinbo commented
在下面的情况下注解没有获取到值:
@Component
@ServerEndpoint("/socket")
public class Server {
private Logger logger = LoggerFactory.getLogger(Server.class);
@XxlConf("cztech.port")
public String port;
@OnOpen
public void onOpen(Session session){
logger.info("port 为"+port);
logger.info ("client is "+ XxlConfClient.get("cztech.port"));
logger.info("有连接建立");
}
}
@RestController
public class HelloController {
@XxlConf("cztech.name")
public String name;
@XxlConf("cztech.port")
private String port;
@GetMapping("/hello")
public String hello(){
return "hello"+name+port;
}
}
xuxueli commented
你好,这个问题是 “ServerEndpoint与Spring的兼容性问题” 导致的。有两种解决方案:
1、使用API的方式 “XxlConfClient.get” 获取XXL-CONF的配置;
2、修复 “Spring Cloud/Boot WebSocket 无法注入Bean的问题”,可参考文档:https://blog.csdn.net/tornadojava/article/details/78781474
wuxinbo commented
好的