抽象類是無法被Spring實例化的,因此無法添加@Service 或 @Componet 註解
如果結果該問題,把需要引用的對象的方法,轉換爲靜態方法
示例:
1 ** 2 * AbstractSignHandler 抽象類無法實例化,因此這裏定義了靜態方法實現文件上傳接口 3 * 4 * @author huahua035 5 * @date 2022-03-02 17:51 6 */ 7 @Service 8 public class DefaultUploadUtilService implements InitializingBean { 9 //切換OBS文件上傳的標識符 10 @Value("${obs.upload.switch:true}") 11 boolean obsSwitch; 12 13 static boolean updateSwitch; 14 static OBSFeginClient obsFeginClient; 15 16 //================ 初始化靜態參數 =================== 17 @Autowired 18 public void setObsFeginClient(OBSFeginClient obsFeginClient) { 19 DefaultUploadUtilService.obsFeginClient = obsFeginClient; 20 } 21 22 @Override 23 public void afterPropertiesSet() throws Exception { 24 updateSwitch = obsSwitch; 25 } 26 27 public static String uploadSignedFile(byte[] signedFile) { 28 29 }
推薦:https://zhuanlan.zhihu.com/p/161223943