注入方式:
@Slf4j
@Component
public class BootNettyChannelInboundHandlerAdapter extends ChannelInboundHandlerAdapter {
public static BootNettyChannelInboundHandlerAdapter
bootNettyChannelInboundHandlerAdapter;
//1.正常注入[记得主类也需要使用@Component注解]
@Autowired
private DeviceUpService deviceUpService;
//2.初始化构造方法一定要有
public BootNettyChannelInboundHandlerAdapter() {
}
//3.容器初始化的时候进行执行-这里是重点
@PostConstruct
public void init() {
bootNettyChannelInboundHandlerAdapter = this;
bootNettyChannelInboundHandlerAdapter.deviceUpService = this.deviceUpService;
}
}
完成以上步骤后通过
bootNettyChannelInboundHandlerAdapter.deviceUpService
调用service类即可