@AutoWired注解使用时可能会发生的错误
@Autowired注解:用于对Bean的属性变量、属性的set方法及构造函数进行标注,配合对应的注解处理器完成Bean的自动配置工作。@Autowired注解默认按照Bean类型进行装配。
1、在applicationContext.xml文件中的<beans>标签里填写xsi:schemaLocation的时候,对引进的包的版本与填写的location的版本不对应。
像是,本来引进的包是"spring-context-3.2.5.RELEASE.jar",版本是3.2.5,但是在xsi:schemaLocation中填入的地址的是"http://www.springframework.org/schema/context/spring-context-4.2.xsd",那就有可能会发生错误。
2、在使用@Autowired注解的时候,没有把实体类之前setter方法删除掉。
3、在使用@Autowired注解之后没有在applicationContext.xml进行<context:component-scan>元素的配置。
因为<context:component-scan>元素会自动注册AuthowiredAnnotationBeanPostProcessor实例(使用Autowired注解必须要注册AutowiredAnnotationBeanPostProcessor实例,用于解析@Autowired注解)。
4、在没有使用<context:component-scan>元素配置的情况下,还没有用<bean>标签对AuthowiredAnnotationBeanPostProcessor进行注册。即:
<bean class="org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor"/>
5、在没使用@Autowired注解配置之前,在applicationContext.xml就写好了注入实例的<prototype>元素,但是在使用@Authowired注解之后需要把<prototype>元素删除。
因为该配置好的元素@Autowired注解已经在底层做好了。
@AutoWired注解使用时可能会发生的错误的更多相关文章
- [备忘][转]rsync使用时的常见问题
sync使用时的常见问题: 错误1: rsync: read error: Connection reset by peer (104) rsync error: error in rsync pro ...
- python基本使用时常见错误
python基本使用时常见错误 字符编码错误 如果要学习计算机编程语言,首先就要搞懂字符编码,否则在以后的学习过程中,将会是一场噩梦.在一开始使用的时候,我就遇到了很多的关于字符编码的问题,做个简单的 ...
- spring boot 中@Autowired注解无法自动注入的错误
版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/huihuilovei/article/de ...
- pygame模块使用时出现AttributeError: module ‘pygame’ has no attribute '…'错误解决方法
pygame模块使用时出现AttributeError: module 'pygame' has no attribute '-'错误解决方法 首先在pygame中存在init()模块,出现这样的问题 ...
- 【SpringMVC】<context:include-filter>和<context:exclude-filter>使用时要注意的地方
http://jinnianshilongnian.iteye.com/blog/1762632 http://blog.51cto.com/wenshengzhu/1700340 http://ww ...
- <context:component-scan>子标签:<context:include-filter>和<context:exclude-filter>使用时要注意的地方
在Spring MVC中的配置中一般会遇到这两个标签,作为<context:component-scan>的子标签出现. 但在使用时要注意一下几点: 1.在很多配置中一般都会吧Spring ...
- @Autowired注解和启动自动扫描的三种方式(spring bean配置自动扫描功能的三种方式)
前言: @Autowired注解代码定义 @Target({ElementType.CONSTRUCTOR, ElementType.FIELD, ElementType.METHOD, Elemen ...
- Spring @Autowired 注解自动注入流程是怎么样?
面试中碰到面试官问:"Spring 注解是如果工作的?",当前我一惊,完了这不触及到我的知识误区了吗?,还好我机智,灵机一动回了句:Spring 注解的工作流程倒还没有看到,但是我 ...
- @Autowired注解的使用
使用Spring时,通过Spring注入的Bean一般都被定义成private,并且要有getter和setter方法,显得比较繁琐,增加了代码量,而且有时会搞忘造成错误. 可以使用@Autowire ...
随机推荐
- codeforces#536题解
CodeForces#536 A. Lunar New Year and Cross Counting Description: Lunar New Year is approaching, and ...
- java调用POI读取Excel
HSSFWorkbook:是操作Excel2003以前(包括2003)的版本,扩展名是.xls:XSSFWorkbook:是操作Excel2007的版本,扩展名是.xlsx: 1.注意点 getPhy ...
- DispatcherServlet详解
1.1.DispatcherServlet作用 DispatcherServlet是前端控制器设计模式的实现,提供Spring Web MVC的集中访问点,而且负责职责的分派,而且与Spring Io ...
- 668. Kth Smallest Number in Multiplication Table
Nearly every one have used the Multiplication Table. But could you find out the k-th smallest number ...
- Java 虚拟机(Java Virtual Machine)
Java 编译器将 Java 程序编译成虚拟机能够识别的二进制代码,这种代码称为字节码(Bytecode).字节码就是虚拟机的机器指令,它与平台无关,有统一的格式,不依赖于具体的硬件环境,只运行在 J ...
- perl C/C++ 扩展(一)
通过h2xs 中间件,我们可以快速的使用c或则C++ 库来实现perl 扩展功能 第一讲:跑通hello world 程序******************************我们使用命令:h2 ...
- 自然语言处理(五)——实现机器翻译Seq2Seq完整经过
参考书 <TensorFlow:实战Google深度学习框架>(第2版) 我只能说这本书太烂了,看完这本书中关于自然语言处理的内容,代码全部敲了一遍,感觉学的很绝望,代码也运行不了. 具体 ...
- (转)关于MongoDB你需要知道的几件事
本文列举了颇让作者困惑的一些MongoDB限制,如果你也打算使用MongoDB,那么至少要提前了解这些限制,以免遇到的时候措手不及. 消耗磁盘空间 这是我的第一个困惑:MongoDB会消耗太多的磁盘空 ...
- bzoj1339/1163:[Baltic2008]Mafia
传送门 最小割,割点,模板... 代码: #include<cstdio> #include<iostream> #include<algorithm> #incl ...
- ZOJ 4033 CONTINUE...?(The 15th Zhejiang Provincial Collegiate Programming Contest Sponsored by TuSimple)
#include <iostream> #include <algorithm> using namespace std; ; int a[maxn]; int main(){ ...