Pu Zhibing
2025-03-07 297512bc22b179b7038d96a1ff033eceaed38c4b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.ruoyi.dataInterchange.netty.server;
 
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import javax.annotation.PostConstruct;
 
/**
 * @author zhibing.pu
 * @Date 2025/3/3 20:06
 */
@Slf4j
@Component
public class NettyStart {
    
    @Autowired
    private ServerBootstrap serverBootstrap;
    
    private int nettyPort = 1000;
    
    private ChannelFuture serverChannelFuture;
    
    @PostConstruct
    public void start() throws Exception {
        log.info("Netty服务启动成功:" + nettyPort);
        serverChannelFuture = serverBootstrap.bind(nettyPort).sync();
    }
}