spring 中自定义工具类 解决@Autowired为null


注解方式

@Component
public class TimerUtil {

    @Autowired
    private DeptConfigService deptConfigService;

    public static  TimerUtil timerUtil;

    @PostConstruct
    public void init(){
        timerUtil = this;
    }
    
    //使用timerUtil.deptConfigService.xxx 调用即可
    public static void test(){
        List deptIdList = timerUtil.deptConfigService.getDeptIdByIfDelNotice();
        System.out.println(deptIdList);
    }
   
}

xml配置方式

在spring-comtext.xml中配置以下bean就好了