工具类注入需要的service
/** * 从redis获取信息 * @author yy * */ @Component//关键一:添加此注解才能被spring扫描到 public class CacheUtil { private static Logger logger = LoggerFactory.getLogger(CacheUtil.class); @Autowired private JJWTUtils jwt; //关键二:添加需要的服务类 public static CacheUtil cacheUtil; //关键三:声明一个当前类的静态对象 @PostConstruct //关键四:通过@PostConstruct注解实现注入 public void init() { cacheUtil = this; //cacheUtil.jwtUtils = this.jwtUtils; } /** * 从Redis中获取登录的员工详细信息 * @Title: getRedisEmp * @Description: * @return * @return EmployeVo * @author yy 2019-6-26 16:11:31 */ @SuppressWarnings("unused") private static EmployeVo getRedisEmp(HttpServletRequest request) { EmployeVo emp = null; JwtBodyBean jwtBody = cacheUtil.jwt.getJwtBody(request); if (jwtBody != null) { Long uid = jwtBody.getUid(); Object jsonObj = cacheUtil.jwt.redisService.get(String.valueOf(uid)); if (jsonObj != null) { JSONObject json = JSONObject.parseObject(jsonObj.toString()); emp = new EmployeVo(); try { emp.setEmId(json.getString("emId")); emp.setDepartmentId(json.getString("departmentId")); emp.setEmAccount(json.getString("emAccount")); emp.setEmPassword(json.getString("emPassword")); emp.setUserName(json.getString("userName")); emp.setEmPhone(json.getString("emPhone")); emp.setSeatId(json.getString("seatId")); emp.setEmLevel(json.getIntValue("emLevel")); emp.setCrmUserId(json.getString("crmUserId")); emp.setAcAccount(json.getString("acAccount")); emp.setAcPassword(json.getString("password")); emp.setBs(json.getIntValue("bs")); emp.setTs(json.getString("ts")); } catch (Exception e) { e.printStackTrace(); logger.error("从redis查询员工信息异常!", e.toString()); } } } return emp; } }
转载自 https://blog.csdn.net/loveer0/article/details/83716040