@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 ...
随机推荐
- 为何在有 DOCTYPE 的 HTML 文档之上仍然还会出现混杂模式?
不使用 DOCTYPE 一定会使 HTML 文档处于混杂模式,然而使用了 DOCTYPE,也不一定就能够使文档在所有浏览器中均处于标准模式. DOCTYPE 本身不就是一个“开关”吗?为何在有 DOC ...
- git clone 之后 , 如何复制文件到文件夹 并 上传
1. 关于 _netrc machine github.com login myid password mypassword machine bitbucket.org login myid pass ...
- jQuery EasyUI/TopJUI实现数据表格的增删改查功能(不写js,纯HTML实现!!!)
jQuery EasyUI/TopJUI实现数据表格的增删改查功能(不写js,纯HTML实现!!!) 废话不多说,直接贴上代码 <table id="configEdatagrid&q ...
- MyBatist庖丁解牛(二)
站在巨人的肩膀上 https://blog.csdn.net/xiaokang123456kao/article/details/76228684 一.概述 我们知道,Mybatis实现增删改查需要进 ...
- 上传到git
https://blog.csdn.net/Lucky_LXG/article/details/77849212
- 单片机C基本编程规范
为了提高源程序的质量和可维护性,从而最终提高软件产品生产力,特编写此规范.本标准规定了程序设计人员进行程序设计时必须遵循的规范.本规范主要针对单片机编程语言和08编译器而言,包括排版.注释.命名.变量 ...
- one jar(转)
http://blog.csdn.net/kabini/article/details/1598827
- Log4j2 - java.lang.NoSuchMethodError: com.lmax.disruptor.dsl.Disruptor
问题 项目使用了log4j2,由于使用了全局异步打印日志的方式,还需要引入disruptor的依赖,最后使用的log4j2和disruptor的版本依赖如下: <dependency> & ...
- C# string.Compare()
tring.Compare方法,用来比较2个字符串值得大小 string.Compare(str1, str2, true); 返回值: 1 : str1大于str2 0 : str1等于str2 - ...
- jave之set和get的用法
package com.xxl.api.admin; public class Test { private int score; public int getScore() { return sco ...