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 ...
随机推荐
- 【JEECG技术博文】Local storage & easyui extensions
1. Local storage背景 cookie弊端:同域内http请求都会带cookie,添加带宽和流量:有个数和限制大小(约4K). 在HTML5中,本地存储是一个window的属性.包含loc ...
- C语言数组和函数实例练习(一)
C语言的数组和函数部分的知识,在语法上和Java语法是有所相似的,这里只通过实例总结一些自己感觉需要理解的部分知识. 1.数组 数组中的元素具有相同的数据类型:数组一旦创建,不能被改变:数组中元素在内 ...
- luogu2754 星际转移问题 网络流
题目大意:地球与月球间有可容纳无限人的太空站,还有在太空站与星球间按周期行驶的.有固定容量的太空船,每一艘太空船从一个太空站驶往任一太空站耗时均为 1.地球上有一定数量的人,问所有人到月球最少需要多少 ...
- Date and time types
https://docs.microsoft.com/en-us/sql/t-sql/data-types/date-and-time-types date (Transact-SQL)datetim ...
- SpringBoot之表单验证@Valid
转自:https://www.cnblogs.com/chenlove/p/8708627.html SpringBoot提供了强大的表单验证功能实现,给我们省去了写验证的麻烦: 这里我们给下实例,提 ...
- 南海区行政审批管理系统接口规范v0.3(规划)
1. 会话API 1.1. login [登录验证] {"r_code":"500","r_msg":"操作失败",&q ...
- BZOJ 2140 Tarjan
思路: 跟POJ有一道时限挺长的题一模一样 哦 POJ 1904 题解可以看这个(捂脸) http://blog.csdn.net/qq_31785871/article/details/52963 ...
- linux下创建公钥
# linux下创建公钥 链接地址:https://www.cnblogs.com/ibyte/p/6086630.html 示例: scp -r /home/yutang/.ssh/id_rsa.p ...
- WinForm导出DataSet到Excel
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- 个人网站html5雪花飘落代码JS特效下载
如何给自己的网站/页面添加雪花代码.特效呢?有的网站配合自己的主题模板添加雪花飘落效果挺好看的.特别是与冬天季节相关的主题,很多的博客空间都加了雪花的效果.在网上搜索了几种雪花效果,做了简单的修改,在 ...