工具类注入需要的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
工具类注入需要的service的更多相关文章
- SpringBoot整合axis1.4后,@Autowired注入失败,使用工具类注入
问题描述: 费劲心思搭建好webservices服务端后,没想到客户端调用失败,查看日志文件,发现报空指针异常,debug代码后,发现sql查询的值都是null.通常情况下,我们将Dao注入Servi ...
- 静态工具类注入service的方法
http://blog.sina.com.cn/s/blog_6e2d53050102wl3x.html
- 【SpingBoot】spring静态工具类注入问题
package cn.zwqh.action; import javax.annotation.PostConstruct; import javax.annotation.Resource; imp ...
- 工具类中注入service和dao
今天编写了个工具类需要用到service成和dao层的代码 如下: //第一步:需要将工具类注入到容器中 @Component public class RuleUtils { //第二部注入 @ ...
- 可以随时拿取spring容器中Bean的工具类
前言 在Spring帮我们管理bean后,编写一些工具类的时候需要从容器中拿到一些对象来做一些操作,比如字典缓存工具类,在没有找到字典缓存时,需要dao对象从数据库load一次,再次存入缓存中.此时需 ...
- 静态工具类中使用注解注入service
转载:http://blog.csdn.net/p793049488/article/details/37819121 一般需要在一个工具类中使用@Autowired 注解注入一个service.但是 ...
- 关于工具类静态方法调用@Autowired注入的service类问题
@Component //此处注解不能省却(0) 1 public class NtClient { 2 /** 3 * 日志 4 */ 5 private static String clazzNa ...
- Spring注入service为null另类解决办法 工具类 一般类 静态 非controller
系统为SpringMVC框架,在开发的过程中有一些工具类需要调用下由spring管理的service层.但是一进注入不进来,报null异常: 在尝试了网上的一系列方法后,还是没有解决.网上的解决方法主 ...
- 静态工具类中使用注解注入service实例
一般需要在一个工具类中使用@Autowired 注解注入一个service.但是由于工具类方法一般都写成static,所以直接注入就存在问题. 使用如下方式可以解决: /** * */ package ...
随机推荐
- 网易云音乐ncm加密格式批量转换为flac,mp3
从网易云下载的某些付费歌曲下载下来会是ncm格式.ncm是个啥?就是你下完一首歌被网易云加密成它自己独有的ncm格式,这个ncm不能在其他播放器播放,如果网易云你会员到期了同样也会提示你无法播放(不是 ...
- ASE19团队项目alpha阶段model组 scrum7 记录
本次会议于11月11日,19时整在微软北京西二号楼sky garden召开,持续15分钟. 与会人员:Jiyan He, Kun Yan, Lei Chai, Linfeng Qi, Xueqing ...
- set 集合的函数调用
方法 意义 S.add(e) 在集合中添加一个新的元素e:如果元素已经存在,则不添加 S.remove(e) 从集合中删除一个元素,如果元素不存在于集合中,则会产生一个KeyError错误 S.dis ...
- 【leetcode】617. Merge Two Binary Trees
原题 Given two binary trees and imagine that when you put one of them to cover the other, some nodes o ...
- RobHess的SIFT代码解析步骤二
平台:win10 x64 +VS 2015专业版 +opencv-2.4.11 + gtk_-bundle_2.24.10_win32 主要参考:1.代码:RobHess的SIFT源码 2.书:王永明 ...
- web开发:定位布局
一.盒子的显隐 二.小米topbar 三.相对定位 四.决定定位 五.固定定位 六.z-index属性 七.流式布局思想 八.hover父子悬浮 一.盒子的显隐 1.同一结构下, 如果采用浮动布局,所 ...
- linux-2.6.38poll机制简析(以tiny6410按键中断程序为基础)
一.应用程序 /* struct pollfd { int fd; //文件描述符 short events; //表示请求检测的事件 short revents; //表示检测之后返回的事件 }; ...
- Istio调用链埋点原理剖析—是否真的“零修改”分享实录(下)
调用链原理和场景 正如Service Mesh的诞生是为了解决大规模分布式服务访问的治理问题,调用链的出现也是为了对应于大规模的复杂的分布式系统运行中碰到的故障定位定界问题.大量的服务调用.跨进程.跨 ...
- 编译teamtalk遇到的问题
一.编译log4cxx遇到的问题 1.error: narrowing conversion 这是在gcc-6下面一个官方的错误 解决方法 https://issues.apache.org/jira ...
- esxi克隆虚拟机
1.->选中虚拟机->导出(需要关闭虚拟机电源) 此时会下载下两个文件: 2.新建虚拟机 ->从OVF或OVA文件部署虚拟机 然后创建虚拟机,选择第二项 然后填入新虚拟机名称,并把下 ...