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 ...
随机推荐
- Shiro学习之身份验证
身份验证,即在应用中谁能证明他就是他本人.一般提供如他们的身份ID一些标识信息来表明他就是他本人,如提供身份证,用户名/密码来证明. 在shiro中,用户需要提供principals (身份)和cre ...
- attr设置checked,disabled等属性失效的问题,jquery的attr和prop的区别
最近做项目遇到一个问题,radio设置了默认checked值,attr("checked",true)切换checked值失效 最后发现是jquery1.6版本之后,attr和pr ...
- On-Heap与Off-Heap
和C#里的托管代码.非托管代码类似
- 【批处理】shift用法举例
@echo off set sum=0 call :sub sum 1 2 3 4 echo sum=%sum% pause :sub set /a %1=%1+%2 shift /2 if not ...
- iOS知识点集合--更改(2)
3.nsmutablearray *a 如果直接赋值 a = @[@"d",@""]; 这个时候a 是不可变的 字典也是如此 2.如果接口调用错误的话 打印re ...
- C++ 头文件系列(iostream)
1. 简介 这个头文件非常特殊,它只声明了8个常用流对象. 2. 8个对象 2.1 窄字符对象(char) extern istream cin extern ostream cout extern ...
- canvas学习api
1.canvas.getContext():获取渲染上下文和绘画功能: 一.绘制矩形 2.ctx.fillRect(x,y,width,height):绘制矩形: 3.ctx.strokeRect(x ...
- Docker(三):Docker仓库配置
1.仓库介绍 仓库(repository)用来集中管理Docker镜像,支持镜像分发和更新. 目前世界上最大最知名的公共仓库是Docker官方的Docker Hub,国内比较知名的有:Docker P ...
- CSS3 使用选择器在页面插入内容
使用选择器来插入文字 h2:before{ content:'COLUMN'; color:white: background-color:orange: padding:1px 5px; } 注意点 ...
- Visual Representation of SQL Joins
原文:http://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins 从视图上介绍了7种不同类型的JOIN ...