关于NoSuchBeanDefinitionException: No bean named 'xxxx' is defined问题解决
2015-06-09 10:28
519 查看
问题如下
查阅了网上关于IoC的资料后,明白了一些这方面的知识。这里单刀直入的给出解决方法。
楼主是在UserController中使用了如下代码
为了找到这个接口的实现类,我们需要知道两点。1、有这个借口的实现类存在;2、怎么找到它。
楼主定义的类和实现的类如下图所示
![](http://img.blog.csdn.net/20150609103518743?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvVGFicmlzX2s=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
包错的意思大致是没有找到userDao的实现。
在spring下创建spring-bean.xml,并在该文件中定义映射关系
![](http://img.blog.csdn.net/20150609105229942?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvVGFicmlzX2s=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
文件内容
此时没完。工程的context依旧是root-context.xml。进入web.xml修改配置信息。由于楼主工程还有spring-hibernate.xml需要作为context
。因此此处改为spring-*.xml。
重新发布。发现登录时404。打开Console,发现在发布时已经报错。错误很长,截取重点部分
Error creating bean with name 'txPointcut': Instantiation of bean failed;
似乎又是bean初始化失败。但是本工程并没有使用过txPointcut这个bean。想起楼主的spring-hibernat.xml是复制其他工程的。进入ctrl+f发现如下内容
将其注销。一切正常。
NoSuchBeanDefinitionException: No bean named 'userDao' is defined
查阅了网上关于IoC的资料后,明白了一些这方面的知识。这里单刀直入的给出解决方法。
楼主是在UserController中使用了如下代码
@Resource(name = "userDao") private UserDao userDao;
为了找到这个接口的实现类,我们需要知道两点。1、有这个借口的实现类存在;2、怎么找到它。
楼主定义的类和实现的类如下图所示
包错的意思大致是没有找到userDao的实现。
在spring下创建spring-bean.xml,并在该文件中定义映射关系
文件内容
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:context="http://www.springframework.org/schema/context" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd"> <bean id="userDao" class="cn.tabris.demo.daoImpl.UserDaoImpl"> <property name="sessionFactory" ref="sessionFactory"></property> </bean> </beans>
此时没完。工程的context依旧是root-context.xml。进入web.xml修改配置信息。由于楼主工程还有spring-hibernate.xml需要作为context
。因此此处改为spring-*.xml。
<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/spring/spring-*.xml</param-value> </context-param>
重新发布。发现登录时404。打开Console,发现在发布时已经报错。错误很长,截取重点部分
Error creating bean with name 'txPointcut': Instantiation of bean failed;
似乎又是bean初始化失败。但是本工程并没有使用过txPointcut这个bean。想起楼主的spring-hibernat.xml是复制其他工程的。进入ctrl+f发现如下内容
<aop:config expose-proxy="true"> <!-- 只对业务逻辑层实施事务 --> <aop:pointcut id="txPointcut" expression="execution(* com.lei.demo.service..*.*(..))" /> <!-- Advisor定义,切入点和通知分别为txPointcut、txAdvice --> <aop:advisor pointcut-ref="txPointcut" advice-ref="txAdvice"/> </aop:config>
将其注销。一切正常。
相关文章推荐
- 墨菲定律、二八法则、马修、手表定理、“不肖”法、彼得原理、零和游戏、华盛顿合作规律、酒与污水定律、水桶定律、蘑菇管理原则、钱的问题、奥卡姆剃刀等。13文章是关于生活的金科玉律
- css字体转换程序(Node.js)
- 括号匹配 分类: 栈和队列 2015-06-09 10:28 15人阅读 评论(0) 收藏
- 在Linux 中 echo命令 让字体带颜色\033[0-7;30-37;40-47;m string \033[0m
- 极光IM 与极光推送紧密结合相信会亮点让你心动
- Android 调用QQ登录
- (R-CNN)Rich feature hierarchies for accurate object detection and semantic segmentation
- c# 操作excel(1)
- flexpaper常用参数
- 基于nodejs的开发环境搭建
- iOS 捕获程序崩溃日志
- Eclipse下properties文件中文乱码的解决方案
- Myelipse如何最佳设置
- Cocos2d-x 3.2 自动更新 -- 使用AssetsManager更新游戏资源包
- 认识自己——不要逼人太甚。
- tomcate 端口号占用,Windows的解决方法
- 2个硬盘对拷操作图解步骤
- C++Primer笔记
- 数据挖掘10大算法(6)-K最近邻(KNN)算法的实现(java和python版)
- 一个 MVC + 三层结构,基于数据库的Web商用系统,通用架构,请看图,,