参考:Springboot @Component下@Autowired的注入为null【转】
1.private static 当前component
2.PostConstruct实例化
3.调用
例:
@Component
public class GrayScaleSubscribeListener extends BasicSubscribeListener {
@Autowired
private IWebhookService webhookService;
@Autowired
private IWebhookSettingsService webhookSettingsService;
private static GrayScaleSubscribeListener grayScaleListener;
@PostConstruct
public void initGrayScale() {
grayScaleListener = this;
grayScaleListener.webhookService = this.webhookService;
grayScaleListener.webhookSettingsService = this.webhookSettingsService;
}
具体调用
grayScaleListener.webhookSettingsService.getOne(queryWrapper);