@Component public class CommMain{ @Autowired public SysTransRecordCommonService sysTransRecordCommonService; public void saveTrans(SysTransRecord sysTransRecord){ sysTransRecordCommonService.save(sysTransRecord); } }
出现无法正常注入的情况,网上找了很多方法,最终以下这种方法亲测可用!
@Component public class CommMain { @Autowired public SysTransRecordCommonService sysTransRecordCommonService; public static CommMain commMain; @PostConstruct public void init(){ commMain = this; commMain.sysTransRecordCommonService = this.sysTransRecordCommonService; } public void saveTrans(SysTransRecord sysTransRecord){ commMain.sysTransRecordCommonService.save(sysTransRecord); } }
好了,亲测可以正常存表!
原文地址:https://www.cnblogs.com/dark-passion/p/10709625.html
时间: 2024-10-06 07:32:36