Spring学习系列:错误记录(一):Spring注解错误记录
来源:互联网 发布:mac恢复出厂系统版本 编辑:程序博客网 时间:2024/05/17 09:19
错误提示
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'loginController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void com.yeonon.web.LoginController.setUserService(com.yeonon.service.UserService); nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.yeonon.service.UserService] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
这是运行后浏览器中的错误提示,在IDEA中也是一样的。
从字面上来看,似乎是无法注解注入,原因是找不到对应的bean,但是我多次查看定义bean的XML文件中并没有发现错误,而且单元测试那里用到了UserService的注解,并完美通过,这就让我很诧异。
问题排查
Google了很长时间,终于在一篇文章中找到了原因,文章说到不仅仅要检查定义bean,还要看看监听器部分,这让我看到了希望。
问题解决
问题就在这里了,监听器本应是ContextLoaderListener,而我这里写成了ContextCleanupListener,两者大不相同。改过来之后,Web能正常的运行了。
应该是写代码的时候图快(用IDEA自动补全),不仔细看导致的。
(IDEA自动补全是好,但是也要看清哈)
ContextCleanupListener是什么
为了不在同一个地方跌倒,我特意去查了一下官方文档,ContextCleanupListener是个什么东西。
Web application listener that cleans up remaining disposable attributes in the ServletContext, i.e. attributes which implement DisposableBean and haven't been removed before. This is typically used for destroying objects in "application" scope, for which the lifecycle implies destruction at the very end of the web application's shutdown phase.
这是文档中写的,从字面上看,似乎是显示的销毁一个对象。(英语水平有限,如有错误,感谢指正!),这就很可怕了,如果在还没创建就销毁,就很难发现问题,DEBUG相当麻烦了。
初学Spring,以上描述如有错误或不足,感谢指正。
阅读全文
0 0
- Spring学习系列:错误记录(一):Spring注解错误记录
- spring 学习 错误记录
- Spring学习系列 : 错误记录(三) MyBatis日期读取
- Spring配置错误记录
- spring常见错误记录
- spring学习记录(一)
- spring-security错误记录(1)
- spring-security错误记录(2)
- 工作记录之Spring学习记录(5)注解开发
- Spring学习系列:错误记录(二) : 类路径和resource目录的关系
- 错误记录(一)
- SSH学习记录之Spring(一)
- 【Spring AOP】学习记录(一)
- 我的Spring学习记录(一)
- Spring部分注解记录
- Spring-注解配置错误(测试错误)
- spring data jpa使用错误记录
- 记录学习的点滴(Spring+MyBatis注解配置)
- java8与并行
- bzoj1008 [HNOI2008]越狱(组合数学+快速幂)
- 第五章 C++与STL入门
- python函数参数
- qt开发环境
- Spring学习系列:错误记录(一):Spring注解错误记录
- APUE之线程创建与终止
- 埃及分数
- Codeforces Round #425 (Div. 2) A
- luogu1965 【2013提高】转圈游戏(快速幂)
- module.export exports的区别
- JDBC详解
- 利用时间戳获取想要的时间
- java使用poi读取xlsx格式的Excel总结