1.需求
在工作中常常会有在工具类中使用数据库数据的情景,工具类中方法通常是静态方法,所以问题来了,静态方法中是不能引用mapper或者service的。废话不说,上代码。
2.代码
package com.noahedu.education.persistences;
import com.noahedu.download.mapper.CacheMapper;
import com.noahedu.download.util.SpringUtil;
import java.util.List;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* Class DictionariesHelper application-context.xml 配置随项目启动加载机型字典 <bean id="productCache"
* lazy-init="false" class="com.noahedu.education.persistences.DictionariesHelper"
* init-method="productDictionaryInit"/>
*
* @author gaobo
* @