spring不能直接注入靜態屬性,不然會一直報空指針異常。
所以今天寫工具類的時候耽誤了很久才解決,最后是使用setter注入
@Component
class ParamsUtils {
? ? ? ?private static CodeService codeService;
? ? ? @Resource
? ? ? ?public void setCodeService(CodeService codeService) {
? ? ? ? ? ? ? ?ParamsUtils.codeService = codeService;
? ? ? ? ?}
? ? ?public static String getParam(){
? ? ? ? ? ?List<Code>? ?list = codeService.findCode();
? ? ? ? ? ? XXXXXXXX
? ? ? }
}