java普通类(非Controller、Service类)中注入service为null 2022-07-02 12:17:44 问题:工作中,出现一个问题。在一个工具类中,@Autowired注解注入Service或者mapper,service, mapper为null?解决步骤: 借鉴了网上其他大佬的解决办法,记录一下 第一步:工具类上面加@Component注解第二步: 静态初使化当前类 第三步:工具类中写一个init方法,并在方法上面加上注解 @PostConstruct第四步: testUtils.xxxmapper.方法" 就可以了