場景描述:
我的項目是 springboot 項目
在工具類裏面使用@Autowired 注入service,dao,或者 restTemplate 都是 null,
同樣,使用 @Value 引用配置文件中的變量也是 null
解決方法:
首先,要在工具類上加上註解 @Configuration
然後定義一個自身的 static 變量,
public static SpeechTranscriberWithMicrophoneDemo speech;
@PostConstruct
public void init() {
speech = this;
}
最後,使用的時候:
speech.summaryParagraphsMapper;
speech.writeFileUrl;
分析:
空閒時間補充