nested exception is org.springframework.beans.factory.BeanCreationException: 不能注入对象 创建对象失败 spring
【出现错误的背景】
在使用Spring+SpringMVC+Mybatis SSM集成框架时,服务器启动就会报错。
【错误根源】
XML配置错误。
【解决方案】
第一步、查找springmvc.xml 配置文件中 是否添加了扫描注解的范围。
<!-- 开启扫描注解 -->
<context:component-scan base-package=""></context:component-scan>
(重要)base-package中要添加扫描注解范围。
<!-- 开启扫描注解 -->
<context:component-scan base-package="com.hyh.action,com.hyh.service.impl"></context:component-scan>
如果上一步没问题的话,看下面
第二步、检查mapper包中的xml。

<mapper >
<!-- 完成用户的账户信息验证 -->
<select id="userLogin" parameterType="com.hyh.entity.User"
resultType="com.hyh.entity.User">
select * from userInfo where phone=#{phone} and accoundpwd=#{accountpwd}
</select> </mapper>

(重要)mapper 标签中,一定要写namespace。
如下:

<mapper namespace="com.hyh.mapper.UserMapper">
<!-- 完成用户的账户信息验证 -->
<select id="userLogin" parameterType="com.hyh.entity.User"
resultType="com.hyh.entity.User">
select * from userInfo where phone=#{phone} and accoundpwd=#{accountpwd}
</select>
</mapper>

一般出现这些问题,无非是粗心、粗心、还是粗心。
另外一定要记住:有些关键字,能复制就复制,打字容易错。
,com.taotao.search.dao
我的错误 项目是sso的maven结构,然后在搭建solr服务的时候多添加了一个dao层的注入,用到注解@Repository,然而我的springmvc中扫描注解是<context:component-scan base-package="com.taotao.search.service"/>,只是<!-- 配置包扫描器,扫描所有带@Service注解的类 -->,在serviceimpl注入dao层对象,就会报创建对象错误,注入对象失败,改为<context:component-scan base-package="com.taotao.search.service,com.taotao.search.dao"/>,启动项目错误消失。
nested exception is org.springframework.beans.factory.BeanCreationException: 不能注入对象 创建对象失败 spring的更多相关文章
- Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'mongoOperations'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with na
问题: Springboot 启动时出错,报没法创建bean的错误,看到nested最后是关于mongoTemplate的错误. 过程: 看网上大多说的是修改mongoTemplate的配置,但是sp ...
- nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException
You should autowire interface AbstractManager instead of class MailManager. If you have different im ...
- Error creating bean with name 'student': Unsatisfied dependency expressed through field 'teacher'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating
有 有参构造但是没有无参构造...
- Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener org.springframework.beans.factory.BeanCreationException:
严重: Exception sending context initialized event to listener instance of class org.springframework.we ...
- Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException
Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException. M ...
- 开发Spring过程中几个常见异常(二):Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'a' define
本异常是小编在运行自己另外一篇博文中的例子时遇到的.(附博文:http://www.cnblogs.com/dudududu/p/8482487.html) 完整异常信息: 警告: Exception ...
- 【解决方案】 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userHandler': Injection of resource dependencies failed;
一个错误会浪费好多青春绳命 鉴于此,为了不让大家也走弯路,分享解决方案. [错误代码提示] StandardWrapper.Throwableorg.springframework.beans.fac ...
- 整合SSH时,遇到了org.springframework.beans.factory.BeanCreationException错误
严重: StandardWrapper.Throwableorg.springframework.beans.factory.BeanCreationException: Error creating ...
- Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field
1 错误描述 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.s ...
随机推荐
- Android Studio使用心得
说实话 開始接触这个工具 真的认为非常恶心 毕竟大陆被墙 非常多东西用起来不是非常方便 并且Eclipse转到Android Studio还是一个跨度 废话不多说 以下 讲下我遇到的问题 1. 安 ...
- 【WPF】ComboBoxItem的禁用
需求:下拉列表ComboBox中,要求部分Item不可用.效果是鼠标一上去后不获得焦点,且无法点击. 前台XAML界面: <!-- 下拉列表:省份 --> <ComboBox Gri ...
- u-boot可ping通PC,PC不可ping通u-boot
http://blog.csdn.net/ce123_zhouwei/article/details/7339134 开发板运行U-Boot,在终端下使用Ping命令是能Ping通PC机,但PC机Pi ...
- 云端中间层负载均衡工具 Eureka
亚马逊提供了一个负载均衡工具 Elastic Load Balancer,但针对的是终端用户 Web 流量服务器,而 Eureka 针对的是中间层服务器的负载均衡.AWS 固有的环境,对 IP 地址. ...
- iOS边练边学--通知机制和键盘处理小练习
一.发送通知 NSNotification *note = [NSNotification notificationWithName:@"通知的名称,随便写,例如:你妈叫你回家吃饭" ...
- double类型保留2位小数
double d = 12.2289; java.text.DecimalFormat df = new java.text.DecimalFormat("#.00"); Syst ...
- C++ 数据封装
C++ 数据封装所有的 C++ 程序都有以下两个基本要素: 程序语句(代码):这是程序中执行动作的部分,它们被称为函数.程序数据:数据是程序的信息,会受到程序函数的影响.封装是面向对象编程中的把数据和 ...
- Perl Spreadsheet::WriteExcel 模块自动生成excel 文件
Spreadsheet::WriteExcel 是一个跨平台的生成excel文件的模块, 可以方便的设置单元格内容, 样式, sheet 的名称: 但是默认情况下中文会乱码, 需要用Encode模块进 ...
- 【Java集合的详细研究6】Java 数组
Java 语言中提供的数组是用来存储固定大小的同类型元素. 声明数组变量 double[] myList; // 首选的方法 或 double myList[]; // 效果相同,但不是首选方法 创建 ...
- Json学习一(基础概念知识学习)
1.Json简单介绍 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它使得人们非常easy的进行阅读和编写. 同一时候也方便了机器进行解析和生成.它是基 ...