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"/>,启动项目错误消失。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



猜您在找 Spring AOP:Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException Spring mvc 错误:org.springframework.beans.factory.BeanCreationException org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'xtCsDao': Injection of resource dependencies failed; nested exception is org.springframework.beans.factory.BeanC org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.facto 警告: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error starting Tomcat context. Exception: org.springframework.beans.factory.BeanCreationException Cannot resolve reference to bean 'mongoTemplate' while setting bean property 'mongoOperations'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with na 关于本次【Unsatisfied dependency expressed through field 'iClientFeignEmployeeService'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.oppo】 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [bean.xml]: Invocation of init method failed; nested exception is Context initialization failed org.springframework.beans.factory.BeanCreationException
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM