問題:工作中,出現一個問題。在一個工具類中(非Controller、非Service),@Autowired注解注入Service或者mapper,service, mapper為null?
解決步驟: 借鑒了網上其他大佬的解決辦法,記錄一下
第一步:工具類上面加@Component注解
第二步: 靜態初使化當前類
第三步:工具類中寫一個init方法,並在方法上面加上注解 @PostConstruct @PostConstruct
第四步: mapper.方法" 就可以了
問題:工作中,出現一個問題。在一個工具類中(非Controller、非Service),@Autowired注解注入Service或者mapper,service, mapper為null?
解決步驟: 借鑒了網上其他大佬的解決辦法,記錄一下
第一步:工具類上面加@Component注解
第二步: 靜態初使化當前類
第三步:工具類中寫一個init方法,並在方法上面加上注解 @PostConstruct @PostConstruct
第四步: mapper.方法" 就可以了
本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。