问题一:Could not autowire.No beans of “NamedParameterJdbcTemplate‘ type found.

问题分析:
在 Idea 的 spring 工程里,遇到 Could not autowire.No beans of “NamedParameterJdbcTemplate‘ type found. 的错误提示。但程序的编译和运行都是没有问题的,不影响业务功能。
问题原因:
(1)第一个是 Intellij IDEA 本身工具的问题。这种情况下不用去理会。
(2)在注解上加上:
@Autowired(required = false)

(3)降低 Autowired 检测的级别,将 Severity 的级别由之前的 error 改成 warning 或其它可以忽略的级别。
问题二:Field injection is not recommended

解决办法:
Settings =》 Editor =》 Inspections =》 Spring=》 Spring Core =》 Code=》 Non recommended ‘field’ injections,将 Non recommended 'field' injections勾选掉,如下图:

最终结果:

本文介绍了在Spring工程中遇到`Couldnotautowire.Nobeansof“NamedParameterJdbcTemplate‘typefound.`的错误,但程序仍能正常运行。该问题可能是IntelliJ IDEA工具的显示问题,可通过降低错误级别或使用`@Autowired(required=false)`注解解决。另外,对于不推荐的字段注入问题,可以在设置中关闭相关Inspection,避免此类警告。
4049

被折叠的 条评论
为什么被折叠?



