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注册了两次而已

  • 相关阅读:
    Hadoop权威指南:HDFS-Hadoop存档
    Hadoop权威指南:通过distcp并行复制
    Hadoop权威指南:HDFS-数据流
    Hadoop权威指南:HDFS-目录,查询文件系统,删除文件
    Hadoop权威指南:HDFS-写入数据
    Hadoop权威指南:FSDataInputStream对象
    Linux下使用javac编译
    解决使用Idea/Eclipse编写Hadoop程序包依赖问题
    Ubuntu 修改时区
    Nginx 调试模块 echo-nginx-module
  • 原文地址:https://www.cnblogs.com/bignew/p/13552752.html
Copyright © 2011-2022 走看看