zoukankan      html  css  js  c++  java
  • spring websocket tomcat was websphere9.0 Multiple Endpoints may not be deployed to the same path

    网上说给 去掉 @Configuration , 注释掉 ServerEndpointExporter ,但是  不同环境 不可能 代码乱搞,所以明显是不行的。

    下面贴代码:  主要在注册bean时候 ,做了个判断  @Conditional(value=WebSocketCondition.class)

    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Conditional;
    import org.springframework.context.annotation.Configuration;
    import org.springframework.stereotype.Component;
    import org.springframework.web.socket.server.standard.ServerEndpointExporter;
    import org.springframework.web.socket.server.standard.ServerEndpointRegistration;
    
    @Configuration
    //@Component
    public class EndpointConfig {
        
        @Bean
        public ServerEndpointExporter endpointExporter() {
            return new ServerEndpointExporter();
        }
        /**
         * 在websphere种,无法完成自动注册websocket。
         * 判断WebSocketCondition 是否注册,未注册则执行
         * @return
         */
        @Conditional(value=WebSocketCondition.class)
        @Bean
        public EchoAnnotatedEndpoint echoAnnotatedEndpoint() {
            return new EchoAnnotatedEndpoint(echoService());
        }
    
        @Bean
        public EchoService echoService() {
            return new DefaultEchoService();
        }
    }
    WebSocketCondition
    import javax.servlet.ServletContext;
    
    import org.springframework.context.annotation.Condition;
    import org.springframework.context.annotation.ConditionContext;
    import org.springframework.core.type.AnnotatedTypeMetadata;
    import org.springframework.web.context.support.XmlWebApplicationContext;
    
    public class WebSocketCondition implements Condition{
    
        @Override
        public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {
            XmlWebApplicationContext resourceLoader = (XmlWebApplicationContext) context.getResourceLoader();
            ServletContext servletContext = resourceLoader.getServletContext();
            String serverInfo = servletContext.getServerInfo();
            //tomcat 容器  ,这里可以根据实际业务,自己判断
            if(serverInfo != null && serverInfo.contains("Tomcat")) {
                return false;
            }
            return true;
        }
    
    }

     OK, 问题解决, 说白了,就是bean注册了两次而已

  • 相关阅读:
    认识Python
    MongoDB
    K8S搭建过程随笔_证书CFSSL
    K8S搭建过程随笔_系统初始化
    zabbix4.2Proxy安装文档
    Zabbix4.2Server端部署
    单节点FastDFS与Nginx部署
    Windows Server 2016分层式存储,使用PowerShell修改底层介质类型
    kill命令和killall命令
    Nuget使用时遇到的问题,Solved
  • 原文地址:https://www.cnblogs.com/bignew/p/13552752.html
Copyright © 2011-2022 走看看