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 ...
随机推荐
- Configuring WS-Security UsernameToken and WS-SecureConversation (Symmetric Connection Creation)
Context This procedure provides a detailed process of all necessary steps to secure Web Services wit ...
- itextpdf添加非自带字体(例如微软雅黑)
找到需要的字体,例如 在windows系统中找到需要字体,本例使用微软雅黑,使用C:\\Windows\\Fonts\\msyh.ttf. 代码如下: /** * 创建pdf,使用微软雅黑字体 * * ...
- 搭建angular1 gulp项目(上传到gitup)
(安装好相关的前端环境) 1.新建一个文件夹,名字为angular-gulp,dos命令切换到该目录,输入npm init,继续添上你需要的信息,ok之后目录中多了package.json(管理项目所 ...
- KVO的内部实现以及使用
转载自:http://www.cocoachina.com/applenews/devnews/2014/0107/7667.html KVO是实现Cocoa Bindings的基础,它提供了一种 ...
- [array] leetcode - 41. First Missing Positive - Hard
leetcode - 41. First Missing Positive - Hard descrition Given an unsorted integer array, find the fi ...
- Mybatis篇总结
本文是对慕课网上"搞定SSM开发"路径的系列课程的总结,详细的项目文档和课程总结放在github上了.点击查看 JDBC写法 //sql: String sql = "s ...
- VS源码编译QuaZip(Windows下)
最近写个Qt demo,想要使用压缩和解压多个文件的功能,并不使用额外进程.网上参考了很多资料,发现只有QuaZip比较适合我的需求.但是QuaZip只提供源码,因此需要自己来编译. QuaZip简介 ...
- 开源框架SmartImageView的使用
1.SmartImageView为一个网络图片框架,可以将一个网络URL的图片展示在UI上 2.SmartImageView使用 @1Github上下载源代码 @2拷贝原码到工程src下 @3布局配置 ...
- mysql-5.7.17.msi安装
mysql-5.7.17.msi安装,跟着截图摩擦,一步一步是爪牙,是魔鬼的步伐 开始: 可以创建其他用户 我自己改了日志名
- postgresql 导出函数的方法
先放一条mysql的导出语句 /usr/bin/mysqldump -h127.30.100.33 -P3388 -uname -ppassword --databases databasename ...