天予不洗头 2021-10-22 18:27 采纳率: 0%
浏览 42

Spring boot 整合netty 无法通过autowired 注入redis

网上搜的方法也试过了但是也没用,请帮帮忙

@Component
@Slf4j
@ChannelHandler.Sharable
public class RemoteUpgradeHandler extends SimpleChannelInboundHandler {
public static RemoteUpgradeHandler remoteUpgradeHandler;

private static Map<String, Integer> sendBasiFile = new HashMap<>();
/**
 * 设备长时间不回应 用于记数给设备发送指令
 */
private static Map<String, Integer> sendNum = new HashMap<>();
ApplicationContext applicationContext=SpringUtil.getApplicationContext();
RedisUtil redis=applicationContext.getBean(RedisUtil.class);


@Autowired
private RedisUtil redis;

public RemoteUpgradeHandler(){}

@PostConstruct
public void init(){
    System.out.println("项目handler初始化");
    remoteUpgradeHandler=this;
    remoteUpgradeHandler.redis=this.redis;
}

  • 写回答

1条回答 默认 最新

  • CSDN专家-sinJack 2021-10-22 18:37
    关注
    RedisUtil redis=applicationContext.getBean(RedisUtil.class);
    
    @Autowired
    private RedisUtil redis;
    

    这两种写法同时存在?不能注入有报错吗。

    评论

报告相同问题?

问题事件

  • 创建了问题 10月22日

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办