IDEA 使用@Autowired提示Field injection is not recommended
摘要:IDEA 使用@Autowired提示Field injection is not recommended问题的解决办法。
在使用@Autowired注解进行bean注入,完成自动装配的工作时,IDEA经常会警告Field injection is not recommended。点击查看警告详细:Spring Team recommends : “Always use constuctor based dependency injection in your beans ,Always use assertions for mandatory dependencies”。这句话的意思是Spring团队建议:“在对bean进行依赖注入时,请始终使用构造器注入方式,始终对强制依赖项使用断言”。
但是构造器注入方式就是因为代码不够简洁才被我们弃之不用的,而且用属性注入时,代码位一直运行正常。所以,我们可以忽略这个warning黄牌警告,其解决办法有如下两个:
将@Autowired注解替换为@Resource注解
注解@Resource是先根据Bean的名称去匹配Bean,若获取不到,则根据类型去匹配。而注解@Autowired则是根据类型匹配,若想通过名称匹配,则需要借助Spring的@Qualifier注解。
不检查属性注入
IntelliJ IDEA 版本2021.3.1 (Ultimate Edition)。修改IDEA中Settings或者Performances里面,对属性注入的检查,依次找到:Performances->editor->code style->inspection-> Spring | Spring Core | Code | Non recommended 'field' injections,去掉钩即可,如下图所示:

IDEA 使用@Autowired提示Field injection is not recommended的更多相关文章
- @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上有篇回答: ...
- 【已解决】Field injection is not recommended和Could not autowired. No beans of 'xxx' type found.
目录 问题 解决办法 备注 问题 在项目中,我们使用Spring的@Autowired注解去引入其他类时有时候阿里的编码规约插件就会提示:"Field injection is not re ...
- @Autowired注解警告Field injection is not recommended
在使用spring框架中的依赖注入注解@Autowired时,idea报了一个警告 大部分被警告的代码都是不严谨的地方,所以我深入了解了一下. 被警告的代码如下: @Autowired UserDao ...
- TClientDataSet 提交时提示 Field value Required 但是未提示具体哪个字段。
TClientDataSet 提交时提示 Field value Required 但是未提示具体哪个字段. 这个错误特别麻烦,要使用 midas 控件时,虽然很方便.但是出错了根本找不到原因,特别是 ...
- 导入mysql数据的时候提示Field * doesn't have a default value解决方法
项目使用django+mysql 在linux中使用的是mysql5.7,导入数据提示:Field * doesn't have a default value 想要解决问题就需要知道在mysql5. ...
- SpringBoot 启动的时候提示 Field *** in *** required a bean named 'entityManagerFactory' that could not be found.
错误截图 后面发现原来和入口类代码有关. //@SpringBootApplication(scanBasePackages = {"org.jzc.odata.cboard",& ...
- idea Autowired 提示红色的解决方式
- 利用Lombok编写优雅的spring依赖注入代码,去掉繁人的@Autowired
大家平时使用spring依赖注入,都是怎么写的? @Servicepublic class OrderService {@Autowiredprivate UserService userServic ...
- 解决@Autowired警告
在使用spring框架中的依赖注入注解@Autowired时,idea报了一个警告 被警告的代码如下: @Autowired UserDao userDao; 警告提示信息:Field injecti ...
随机推荐
- 基于自注意力机制的轻量级人体姿态估计(Lightweight Human Pose Estimation Based on Self-Attention Mechanism)
写在前面 本文是一篇于2023年3月21日发表在2023 International Conference on Big Data, Environmental Industry and Materi ...
- NCS开发学习笔记-基础篇-前言
nRF5 SDK 与 nRF Connect SDK 目前Nordic有2套并存的SDK:老的nRF5 SDK和新的nRF Connect SDK(简称NCS),两套SDK相互独立. nRF5 SDK ...
- PHP中处理html相关函数集锦
1.html_entity_decode() 函数把 HTML 实体转换为字符. Html_entity_decode() 是 htmlentities() 的反函数. 例子: <?Php $s ...
- echarts柱形图给X轴坐标类目添加点击事件
在项目中遇到这么个需求要在柱形图上的x轴添加点击事件,当点击对应x轴文字的时候要弹出模态框展示子图表 根据echarts的Api给图表实例绑定点击事件 myChartInstance?.on('cli ...
- gin解决CORS跨域问题
直接设置跨域参数 新建 cors 文件 package cors import ( "time" "github.com/gin-contrib/cors" & ...
- Panabit 流控软件的使用教程
Flow control software-Panabit Howto Version 1.0.0 Date 2010-11-21 Author ipcpu Website http://www.ip ...
- Windows下安装使用OpenLDAP
LDAP:(轻量级目录访问协议,Lightweight Directory Access Protocol)它是基于 X.500标准的,但是简单多了并且可以根据需要定制.与X.500不同,LDAP支持 ...
- Delphi字符串加密解密函数
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ...
- 基于RK3568 + FPGA国产平台的多通道AD实时采集显示方案分享
在工业控制与数据采集领域,高精度的AD采集和实时显示至关重要.今天,我们就来基于瑞芯微RK3568J + FPGA国产平台深入探讨以下,它是如何实现该功能的.适用开发环境如下: Windows开发环境 ...
- 【Linux】3.2 vi和vim编辑器
vi 和 vim 三种模式的相互转化图 vim 和 vi 的快捷键键盘一览图 vi和vim编辑器 1. vi和vim的基本介绍 所有Linux系统都会内置vi文本编辑器 vim是vi的升级版,可以主动 ...