static类型autowired 注入失败
原代码:注入commonService对象失败
@Autowired
private static CommonService commonService; public static List<Map<String, Object>> getCode(String codeType, boolean allOption ,String orderType){
return commonUtil.commonService.getCode(codeType, allOption, orderType);
}
commonService在static状态下不能够被依赖注入,会抛出运行时异常java.lang.NullPointerException,为什么呢?
静态变量/类变量不是对象的属性,而是一个类的属性,spring则是基于对象层面上的依赖注入.
解决方式1:
@Autowired
private CommonService commonService;
private static CommonUtil commonUtil; @PostConstruct
public void init() {
commonUtil = this;
commonUtil.commonService = this.commonService;
} public static List<Map<String, Object>> getCode(String codeType, boolean allOption ,String orderType){
return commonUtil.commonService.getCode(codeType, allOption, orderType);
}
static类型autowired 注入失败的更多相关文章
- 【Intellij idea】spring中@Autowired注入失败
@Autowired注入失败失败的解决办法? 现有的解决的方案是: 打开file-settings或者ctrl+alt+s -> Editor 然后在Inspections 点击搜索栏 输入Sp ...
- spring boot开发 @autowired注入失败
@autowired注入失败 会出现如下错误提示: 2018-05-28 08:39:41.857 INFO 8080 --- [ restartedMain] org.hibernate.Versi ...
- SpringBoot整合axis1.4后,@Autowired注入失败,使用工具类注入
问题描述: 费劲心思搭建好webservices服务端后,没想到客户端调用失败,查看日志文件,发现报空指针异常,debug代码后,发现sql查询的值都是null.通常情况下,我们将Dao注入Servi ...
- 当spring 对象@Autowired 注入失败或者创建对象Bean失败、No qualifying bean/Error creating bean 的失败情形分析和解决方案
错误信息 今天开发的过程中突然出现如下错误: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: N ...
- Spring Autowired 注入失败总是Null
报错:NullPointerException 分析:错误原因是注入失败? <context:annotation-config/> <context:component-scan ...
- Spring @Value取值为null或@Autowired注入失败
@Value 用于注入.properties文件中定义的内容 @Autowired 用于装配bean 用法都很简单,很直接,但是稍不注意就会出错.下面就来说说我遇到的问题. 前两天在项目中遇到了一个问 ...
- Spring security UserDetailsService autowired注入失败错误
最近使用spring mvc + spring security 实现登录权限控制的时候,一直不能成功登录,检查过后是dao一直无法注入为null CustomUserDetailConfig.jav ...
- SSM @Autowired注入失败
1, Intellij IDEA中Mybatis Mapper自动注入警告的6种解决方案 https://blog.csdn.net/weixin_30945319/article/details/9 ...
- 欲哭无泪的@Autowired注入对象为NULL
欲哭无泪啊...一下午的时间就这么被浪费了...一个基于spring mvc和spring data jpa的小项目,当我写完一个controller的测试用例后,一运行却报空指针,跟了下是一个dao ...
随机推荐
- QUERY_REWRITE_INTEGRITY
QUERY_REWRITE_INTEGRITY Property Description Parameter type String Syntax QUERY_REWRITE_INTEGRITY = ...
- maven 自建库
maven repository 标签: mavenjarxmlserver工具磁盘 2009-11-26 10:56 42322人阅读 评论(7) 收藏 举报 目录(?)[+] 什么是Mav ...
- Scrapy源代码分析-经常使用的爬虫类-CrawlSpider(三)
CrawlSpider classscrapy.contrib.spiders.CrawlSpider 爬取一般站点经常使用的spider.其定义了一些规则(rule)来提供跟进link的方便的机制. ...
- cocos2d-x的gitignore配置
# Ignore thumbnails created by windows Thumbs.db # Ignore files build by Visual Studio *.obj *.exe * ...
- 二维数组+字符串split+Double包装类 例题
将String s = "1,2;3,4,5;6,7,8" 存放在double类型的二维数组中,使得 d[0][0]=1.0 d[0][1]=2.0 d[1][0]=3.0 d[1 ...
- DexClassLoader和PathClassLoader类载入机制
0x00 在DexClassLoader和PathClassLoader载入Dex流程一文中,我们分析了dex文件怎样形成了DexFile结构体.本文中解说类载入机制,实际上就是生成ClassObje ...
- CodeForces--621A--Wet Shark and Odd and Even(数学水题)
Wet Shark and Odd and Even Time Limit: 2000MS Memory Limit: 262144KB 64bit IO Format: %I64d & ...
- 树状数组 poj2352 Stars
2019-05-20 22:52:07 加油,坚持,加油,坚持 !!! #include<iostream> #include<cstdio> #include<cstr ...
- H3BPM表单设计器公式设计参考
表单设计器公式设计参考 整体说明 Ø 公式以javascript方式解析,最终支持JS语法或计算方式: Ø 公式变量以数据项为主,以{}符号表示数据项,例如数据项A,表示为{A}:如果是子表中的数据项 ...
- 在APP开发设计过程中:如何设计启动页面?
心理学上有一个“7秒理论”,说的是,一个人对另一个人的印象,在初次见面的七秒内就会形成,最近更有研究表明,这个时间可能更短——不到1秒.所以初次见面所展示的形象真的很重要.同理,用户在使用APP时,每 ...