【已解决】Field injection is not recommended和Could not autowired. No beans of 'xxx' type found.
问题
在项目中,我们使用Spring的@Autowired注解去引入其他类时有时候阿里的编码规约插件就会提示:“Field injection is not recommended”或“Could not autowired. No beans of 'xxx' type found.”,引用类的变量名会有红色的波浪线,虽然不影响程序执行,但是强迫症看着还是难受。


解决办法
将“@Autowired”注解换为“@Resouce”注解。
更换注解后:


备注
@Resource是JSR-250规范中的注解,目前Spring已支持该规范。@Resource是先根据Bean的名称去匹配Bean,获取不到的话再根据类型去匹配;而@Autowired则是根据类型匹配,通过名称则需要Spring的@Qualifier注解配合。
【已解决】Field injection is not recommended和Could not autowired. No beans of 'xxx' type found.的更多相关文章
- @Autowired注解警告Field injection is not recommended
在使用spring框架中的依赖注入注解@Autowired时,idea报了一个警告 大部分被警告的代码都是不严谨的地方,所以我深入了解了一下. 被警告的代码如下: @Autowired UserDao ...
- @Autowired 警告 Field injection is not recommended Spring @Autowired注入
问题: 一. 在IDEA升级2017版后,发现以前使用的 @Autowired 出现了个警告 Field injection is not recommended. @Autowired的三种使用方式 ...
- IntelliJ IDEA:Field injection is not recommended
使用IntelliJ IDEA进行开发的时候,code analyze的时候会出现提示“Field injection is not recommended”. stackoverflow上有篇回答: ...
- IDEA出现Could not autowire. No beans of 'xxx' type found.解决
Plan A File → Project Structure... Facets → Spring → 右键删除即可 Plan B File → Settings → Editor → Inspec ...
- Ubuntu下在Eclipse IDE for C/C++ Developers中怎样执行C语言的GTK程序?(已解决)
(已解决.详见Ubuntu 12.04下在Eclipse IDE for C/C++ Developers中执行C语言的GTK程序) 按"Ubuntu下GTK的安装.编译和測试"( ...
- Microsoft.Office.Interop.Excel, Version=12.0.0.0版本高于引用的程序集(已解决)
Microsoft.Office.Interop.Excel, Version=12.0.0.0版本高于引用的程序集(已解决) 论坛里的帮助:http://bbs.csdn.net/topics/39 ...
- 使用Notepad++编码编译时报错(已解决?)
使用Notepad++编码编译时报错(已解决?) 使用Notepad++编码,编译的时候经常会报错,说什么GBK编码啥啥啥~~~但同样的编码用ECLIPSE就没有问题.再有,用记事本把他保存成ANSI ...
- 已解决】Sublime中运行带input或raw_input的Python代码出错:EOFError: EOF when reading a line(转)
[问题] 在折腾: [已解决]Sublime Text 2中运行Python程序出错:The system cannot find the file specified 的过程中,虽然解决了找不到py ...
- 【已解决】Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory 8
[问题] 折腾: [已解决]Android ADT中增大AVD内存后无法启动:emulator failed to allocate memory 8 过程中,增大对应AVD的内存为2G后,结果无法启 ...
随机推荐
- golang中遍历汇总
直接上例子: 例子1: package main import( "fmt" ) func main(){ a := map[string]string{ "alice& ...
- PowerShell入门学习
一.概要 Powershell是运行在windows机器上实现系统和应用程序管理自动化的命令行脚本环境. powershell需要.NET环境的支持,同时支持.NET对象.之所以将Powershell ...
- phpstorm clone 码云项目到本地 Version Control 不显示
最近在用码云作为代码仓库,但是建了仓库,也填加了 SSH,把项目利用 phpstorm VCS --> checkout from version control --> git 克隆到 ...
- docker mysql容器的安装使用
docker拉取镜像的命令为 docker pull image[:TAG] 如果我们想安装的mysql版本不是最新的版本,则需要填充TAG,如果不带上TAG,则默认安装的为最新版本,虽然可以通过do ...
- Eureka参数配置项详解
Eureka涉及到的参数配置项数量众多,它的很多功能都是通过参数配置来实现的,了解这些参数的含义有助于我们更好的应用Eureka的各种功能,下面对Eureka的配置项做具体介绍,供大家参考. Eure ...
- Laravel中Session的使用
以file为示例 1.Http request session方法$request->session()->put('key1','value1');echo $request->s ...
- easyUI之Dialog(对话框窗口)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <hea ...
- 发送Http请求调用webService
如果调用WebService的不是在.NET中,无法直接添加web引用,那怎么调用webservice. 有两种方式 第一种方式:GET方式 string strUrl = "http:// ...
- Linux环境下warning: no newline at end of file
今天在Windows下VS2012写了一个程序, 然后放在Linux系统下进行编译.Linux下使用的编译器是CC,结果,一编译出现了很多诸如下面的警告信息,似乎每一个.cpp和.h文件都有. Ite ...
- Python - selectors 模块
selectors 模块 它的功能与 linux 的 epoll,还是 select 模块, poll 等类似: 实现高效的 I/O multiplexing , 常用于非阻塞的 socket ...