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 ...
随机推荐
- [深入理解Android卷一全文-第七章]深入理解Audio系统
由于<深入理解Android 卷一>和<深入理解Android卷二>不再出版,而知识的传播不应该由于纸质媒介的问题而中断,所以我将在CSDN博客中全文转发这两本书的全部内容. ...
- PyCharm 运行工程
- Nginx 源码安装和调优
常见web架构: LAMP =Linux+Apache+Mysql+PHP LNMP =Linux+Nginx+Mysql+PHP nginx概述: 知道:1 不知道:2 Nginx (&q ...
- wpf Listbox 设置ItemContainerStyle后,ItemTemplateSelector不能触发
解决方案: 将Listbox 的ItemTemplateSelector 改为 ItemContainerStyle中ContentPresenter ContentTemplateSelector ...
- VUEJS2.0源码理解--优
VUEJS2.0源码理解 http://jiongks.name/blog/vue-code-review/#pingback-112428
- java8新特性系列:[1]让你的eclipse支持java8
package com.anhui.jdk8; /** * 针对eclipse是否支持java8小测试 * MainClass * @author zhongzh * */ public class ...
- 解决 dotnet core 1.x 命令行(cli) 下运行路径错误
环境: Windows 10,Visual Studio 2017 centos 7,nginx,supervisor,dotnet core 1.1 问题: 在 Linux 配置 superviso ...
- [Offer收割]编程练习赛35
有歧义的号码 #include<stdio.h> #include<string.h> #include<stdlib.h> int cmp(const void ...
- Android stroke 边框线 某一边
有时候需要给View加边框线,我们经常是四边一起加,就像这样: <shape xmlns:android="http://schemas.android.com/apk/res/and ...
- wp版笔记本应用源码
今天在那个WP教程网看到了一个不错的项目,简单的记事本,主要是用到的独立存储文件的操作,TimePicker和DatePicker的是用,数据绑定,界面的参考的chanraycode的,主要是锻炼自己 ...