content: package com.codeages.termiusplus.config;
  
  import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
  import org.springframework.boot.web.servlet.ServletContextInitializer;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.socket.server.standard.ServerEndpointExporter;
  import org.springframework.web.util.WebAppRootListener;
  
  import jakarta.servlet.ServletContext;
  
  @Configuration
  @ComponentScan
  @EnableAutoConfiguration
  public class WebSocketConfig implements ServletContextInitializer {
      /**
       * 给spring容器注入这个ServerEndpointExporter对象
       * 相当于xml：
       * <beans>
       * <bean id="serverEndpointExporter" class="org.springframework.web.socket.server.standard.ServerEndpointExporter"/>
       * </beans>
       * <p>
       * 检测所有带有@serverEndpoint注解的bean并注册他们。
       *
       * @return
       */
      @Bean
      public ServerEndpointExporter serverEndpointExporter() {
          return new ServerEndpointExporter();
      }
  
      @Override
      public void onStartup(ServletContext servletContext) {
          servletContext.addListener(WebAppRootListener.class);
          //调整tomcat的websocket缓冲区大小 ，如果要支持 rz sz 之类的命令，需要调整这个缓冲区大小
          servletContext.setInitParameter("org.apache.tomcat.websocket.textBufferSize",
                  String.valueOf(3 * 1024 * 1024));
          servletContext.setInitParameter("org.apache.tomcat.websocket.binaryBufferSize",
                  String.valueOf(3 * 1024 * 1024));
      }
  }
  