spring_netty.xml 1.4 KB

1234567891011121314151617181920212223242526272829
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:context="http://www.springframework.org/schema/context"
  5. xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  6. http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
  7. <!-- 自动扫描websocket下的包 -->
  8. <context:component-scan base-package="com.ncjt.ch.eg.websocket"/>
  9. <!-- 通过spring创建并注入NioEventLoopGroup实例对象 -->
  10. <!-- 用于处理客户端连接请求 -->
  11. <bean id="bossGroup" class="io.netty.channel.nio.NioEventLoopGroup"/>
  12. <!-- 用于处理客户端I/O操作 -->
  13. <bean id="workerGroup" class="io.netty.channel.nio.NioEventLoopGroup"/>
  14. <!-- 服务器启动引导类 -->
  15. <bean id="serverBootstrap" class="io.netty.bootstrap.ServerBootstrap" scope="prototype"/>
  16. <!-- 将WebSocket服务器线程作为bean托管给spring创建 -->
  17. <!-- spring负责创建该类实例对象,并通过依赖注入对对象的成员变量进行赋值 -->
  18. <bean id="webSocketServer" class="com.ncjt.ch.eg.websocket.WebSocketServerThread">
  19. <property name="port" value="7070"/>
  20. <property name="childChannelHandler" ref="egChildHandler" />
  21. </bean>
  22. </beans>