spring @Autowired注入对象,在构造方法中为null问题
出现问题的代码如下:
@Service
public class BaseHttpServiceImpl implements BaseHttpClient { private final static Logger logger = LoggerFactory.getLogger(BaseHttpClient.class); private OkHttpClient mOkHttpClient;
@Autowired
private AthenaConfig configure ;
private CookiesStoreImpl cookiesStoreImpl; /**
* 初始化客户端
*/ public BaseHttpServiceImpl(AthenaConfig configure) {
……
String url=configure.getName("url");
}
}
运行该代码会提示:configure为null 空指针错误
构造器改为:
@Autowired
public BaseHttpServiceImpl(AthenaConfig configure) {
this.configure=configure;
……
}
spring @Autowired注入对象,在构造方法中为null问题的更多相关文章
- Spring @Autowired注解在非Controller中注入为null
问题描述 今天在写一个工具类,里面用了@Autowired注入了StringRedisTemplate以及RedisTemplate时,在template.opsForValue().set(key, ...
- intellij idea中去除@Autowired注入对象的红色波浪线提示
idea中通过@Autowired注入的对象一直有下划线提示. 解决:改变@Autowired的检查级别即可. 快捷键:Ctrl+Alt+s,进入idea设置界面,输入inspections检索
- intellij idea中去除@Autowired注入对象带来的下划线提示
场景: idea中通过@Autowired注入的对象一直有下划线提示,虽然不影响运行 解决:改变@Autowired的检查级别即可. 快捷键:Ctrl+Alt+s,进入idea设置界面,输入inspe ...
- 欲哭无泪的@Autowired注入对象为NULL
欲哭无泪啊...一下午的时间就这么被浪费了...一个基于spring mvc和spring data jpa的小项目,当我写完一个controller的测试用例后,一运行却报空指针,跟了下是一个dao ...
- Quartz定时器+Spring + @Autowired注入 空指针异常
在Quartz的定时方法里引用@Autowired注入Bean,会报空指针错误 解决办法: 第一种方法:(推荐,简单,亲测可行) 使用@Resource(name="指定要注入的Bean&q ...
- @Autowired 警告 Field injection is not recommended Spring @Autowired注入
问题: 一. 在IDEA升级2017版后,发现以前使用的 @Autowired 出现了个警告 Field injection is not recommended. @Autowired的三种使用方式 ...
- Spring @Autowired 注入为 null
原因 配置缺失,比如为开启注解扫描驱动.注入组件为注册: 使用 new 关键字创建的对象不受spring容器管理,无法注入: 注入静态变量, 静态变量/类变量不是对象的属性,而是一个类的属性,spri ...
- spring @Autowired注入map
注入map,平常一般不会这么做,今天看一段老代码时发现有这么个用法.补习一下. @Autowired 标注作用于 Map 类型时,如果 Map 的 key 为 String 类型,则 Spring 会 ...
- Spring Autowired 注入失败总是Null
报错:NullPointerException 分析:错误原因是注入失败? <context:annotation-config/> <context:component-scan ...
随机推荐
- SR-IOV虚拟机的MTU与物理网卡的MTU
在进行SR-IOV虚拟机MTU方面的测试时,出现如下情况: 1)物理网卡PF的MTU值是4000: root@compute-1:~# ip l|more1: lo: <LOOPBACK,UP, ...
- select * from 后有多个表的使用方法
已知一个表的结构为: ------------------- 姓名 科目 成绩 张三 语文 20 张三 数学 30 张三 英语 50 李四 语文 70 李四 数学 60 李四 英语 90 怎样通过 ...
- nginx中try_files
location / { try_files $uri $uri/ /index.php?$query_string; } 当用户请求 http://localhost/example 时,这里的 $ ...
- nginx优化参考
参考链接:http://blog.sina.com.cn/s/blog_4f9fc6e10102uxib.html 计算访问路径频度 awk -r|more |grep /路径 ps print &a ...
- oracle数据库连接 ORA-12638:身份证明检索失败
连数据库的时候突然报了一个这个 查找各种办法,发现自己从10g换成了11g,不过这个没有什么关系,跟oracle的安全设置有关系, 首先从开始菜单找到Net Manager 打开,选择本地,概要文件, ...
- c、c++函数随机
#inlcude<algorithm> next_permutation函数<全排列函数> #include<stdio.h> #include<algori ...
- spring+springMvc+struts的SSH框架整合
1.建立一个web项目 2.导入SSH框架所需jar包 3.配置web.xml文件 <?xml version="1.0" encoding="UTF-8" ...
- java中的线程问题(一)什么是线程。
线程--什么是进程 进程--概念 要解释线程,就必须明白什么是进程. 什么是进程呢? 进程是指运行中的应用程序,每个进程都有自己独立的地址空间(内存空间),比如用户点击桌面的IE浏览器,就启动了一个进 ...
- Vue - v-for 的延伸用法
1.v-for 合并标签template 一起使用 2.vue.set 1.v-for 合并标签template 一起使用 之前在设计table的时候,如果使用v-for ,会直接放在tr里面,一次产 ...
- guava-retrying 源码解析(等待策略详解)
一.等待策略相关类: 1.等待策略接口:WaitStrategy接口 该接口只有一个方法,就是返回尝试失败之后,下一次尝试之前的等待时间.long computeSleepTime(Attempt f ...