springboot 静态方法注入service
springboot项目中无法使用@Autowired注入sevice,需要手动初始化,初始化后才可使用
@Component
public class Utils {
@Autowired
private Service service;
private static Utils utils;
public void setUserInfo(Service service) {
this.service = service;
}
//初始化静态参数
@PostConstruct
public void init() {
utils = this;
utils.service = this.service;
} public static void insertOpeLog(HttpServletRequest req, String str) { ServiceBean bean =new ServiceBean();
utils.service.save(bean); //调用方法}
}
springboot 静态方法注入service的更多相关文章
- springboot 静态方法注入bean、使用@value给static变量赋值
首先新建你的方法类:DemoUtil 头部加注解:@Component @Component public class DemoUtil { } 新增静态变量: static DemoService ...
- Springboot依赖注入 Service类中使用静态变量
@Component public class ServerHandler extends IoHandlerAdapter { @Autowired protected HealthDataServ ...
- SpringBoot 无法注入 service 的 bean
错误信息 Description: Field areaService in com.imooc.demo.web.AreaController required a bean of type 'co ...
- springboot拦截器注入service为空
一般都是因为除了在拦截器之外,还需要在拦截器的配置类中,注册拦截器时没有使用spring的bean,而是使用了new创建bean造成的. @Configuration public class Web ...
- 工具类静态方法注入dao
工具类里的一个静态方法需要调用dao查询数据库,用普通的spring注解注入一直报空指针异常,不能找到这个dao.参考的http://busing.iteye.com/blog/899322 的文章解 ...
- 如何在Java Filter 中注入 Service
在项目中遇到一个问题,在 Filter中注入 Serivce失败,注入的service始终为null.如下所示: public class WeiXinFilter implements Filter ...
- Myeclipse插件快速生成ssh项目并配置注解 在action层注入service的超详细过程
最近发现,我对于ssh的 自动注入配置 还是不熟悉,于是整理了一下 终于做了一个 简单的 注入配置出来. 以前都是在applicationContext.xml 里面这样配 <bean id=& ...
- 关于如何在Listener中注入service和ServletContextListener源码分析
今天在做项目时突然发现我该如何向listener中注入service对象,因为监听器无法使用注解注入. 此时有人会想用以下代码通过xml的方式注入: ApplicationContext cont ...
- spring整合Jersey 无法注入service的问题
现象: action中的@autowired注入service或dao失败,报空指针异常 原因: 造成该问题的原因是你并没有做好spring和jersey的整合工作,检查你的web.xml文件,jer ...
随机推荐
- Javaproject集成log4j 2.x
log4j2和log4j在配置文件和引入jar包上出现了不同.这里做个备忘,这里使用的版本号为apache-log4j-2.3-bin.zip. 1.apache-log4j-2.3-bin.zip下 ...
- [Phonegap+Sencha Touch] 移动开发26 Android下的sencha touch程序,转屏时,Ext.Viewport不能触发orientationchange事件的解决的方法
Sencha touch 2.4.2 已经解决问题了. 比方你为Ext.Viewport的orientationchange事件加入了一个监听方法: Ext.Viewport.on('orientat ...
- matplotlib简介及安装
官网介绍: Matplotlib is a Python 2D plotting library which produces publication quality figures in a var ...
- WebGL学习(3) - 3D模型
原文地址:WebGL学习(3) - 3D模型 相信很多人是以创建逼真酷炫的三维效果为目标而学习webGL的吧,首先我就是
- ViewPager+Fragment 懒加载
转载于: 作者:尹star链接:http://www.jianshu.com/p/c5d29a0c3f4c來源:简书 ViewPager+Fragment的模式再常见不过了,以国民应用微信为例,假 ...
- Mixed Reality-宁波市VR/AR技术应用高研班总结
年,全球AR与VR市场规模将达到1500亿美元,而根据市场研究机构BI Intelligence的统计,2020年仅头戴式VR硬件市场规模将达到28亿美元,未来5年复合增长率超过100%.本次培训从V ...
- docker容器自动退出的问题
如果用了一段时间的docker就会发现,我们的容器经常用了一段时间就自动退出了,docker ps已经找不到了,在docker ps -a里面了,然后我们docker start containerI ...
- JavaScript 中 apply 、call 的详解
apply 和 call 的区别 ECMAScript 规范给所有函数都定义了 call 与 apply 两个方法,它们的应用非常广泛,它们的作用也是一模一样,只是传参的形式有区别而已. 原文作者:林 ...
- jsp上的九个隐含对象
首先说一说件jsp的原理.jsp被认为最经典的解释是 “嵌入了java 代码的html”. 在网上查了一些资料,和我本身对jsp的认识,总结如下: jsp本质上是一个servlet,继承自 当第一次 ...
- 【原码笔记】-- protobuf.js 与 Long.js
protobuf.js的结构和webpack的加载之后的结构很相似.这样的模块化组合是个不错的结构方式.1个是适应了不同的加载方式,2个模块直接很独立.webpack的功能更全一点.但如果自己封装js ...