普通类Autowired为null的情况

@Component // 注入为spring bean
public class TestMsg{
    private static final Logger logger = LoggerFactory.getLogger(TestMsg.class);
    @Autowired
    private TestService testService;
    private static TestMsg testMsg;  // 保存初始化时注入到的testService
   
    public void handlerMessage(MessageVO message) {
        testMsg.testService.doSomething(); // 用testMsg里set的testService去执行service方法
    }
    @PostConstruct
    public void init() {
        testMsg = this;
        testMsg.testService= this.testService;
    }
}
原文地址:https://www.cnblogs.com/jinwenb/p/10408298.html