NutzCN Logo
问答 继承Runnable的类,无法注入
发布于 2439天前 作者 wx_tdsojn7r6hdfbhg0hve8 3252 次浏览 复制 上一个帖子 下一个帖子
标签: nutzwk

业务需求起了一个线程,在线程内处理页面时,bean都无法注入

@IocBean
public class AuctionThread implements Runnable {
    public static Map<String, Integer> map = new HashMap<>();
    @Inject
    private RedisService redisService;
String typr= redisService.get(key);

Exception in thread "Thread-18" java.lang.NullPointerException
at com.speedAuction.listener.AuctionThread.run(AuctionThread.java:51)
at java.lang.Thread.run(Thread.java:745)

1 回复

对象从ioc容器取出来才有注入一说

new Thread(ioc.get(AuctionThread.class)).start();

添加回复
请先登陆
回到顶部