线程类中使用spring注解报空指针异常

springboot项目开发中,作为服务端,实现了线程类,在此类中添加spring注解@Source注入的service,报空指针异常。

查原因后,发现是线程中,不支持spring注解,因为spring默认bean为单例模式构建,为非线程安全的,因此禁止了在Thread子类中的注入行为。

 

posted @ 2019-07-22 17:48  莎影  阅读(728)  评论(0编辑  收藏  举报