SSM框架---容器创建注入对象失败异常之个人原因分析小记

来源:互联网 发布:淘宝订机票 编辑:程序博客网 时间:2024/05/01 02:00
严重: Exception sending context initialized event to listener instance of class 
org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
 'bsxrServiceImpl': Injection of autowired dependencies failed; nested exception is 
org.springframework.beans.factory.BeanCreationException: Could not autowire field: 
private com.bj.dao.BsxrDao com.bj.service.BsxrServiceImpl.dao; nested
 exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
 No qualifying bean of type [com.bj.dao.BsxrDao] found for dependency: 
expected at least 1 bean which qualifies as autowire candidate for this dependency.
 Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
Related cause: org.springframework.beans.factory.BeanCreationException: Error creating bean 
with name 'bsxrDao' defined in file [D:\workspace\.metadata\.plugins\org.eclipse.wst.server.
core\tmp0\wtpwebapps\port_1\WEB-INF\classes\com\bj\dao\BsxrDao.class]: Invocation 

of init method failed; nested exception  。。。。。。。。


这个异常网上有很多说法,各种原因,都没有解决。

Error creating bean with name
 'bsxrServiceImpl'       注解我是使用的@Autowired  ,出现上述异常,困惑了将近一天;


@Autowired 后面加上 (required = false);  不再报 上述异常,但是有新异常
expected com.bj.dao.BsxrDao, but found com.bj.dao,看来是BeanCreationException: Error creating bean with name
 'bsxrServiceImpl':  这个异常把expected com.bj.dao.BsxrDao, but found com.bj.dao异常给掩盖掉了。

@Autowired(required = false)会使expected com.bj.dao.BsxrDao, but found com.bj.dao,看来是BeanCreationException: Error creating bean with name
 'bsxrServiceImpl': 异常不再显示,所以才发现根本原因,并不是spring的配置文件以及注解的错误。


这个异常就简单了,检查发现使用的mapper的动态代理,但是namespace应该写全限定性接口名,自己写错了,,更改后终于解决问题。


总结一句话:

BeanCreationException: Error creating bean with name
 'bsxrServiceImpl':    原因之一就是  mapper动态代理  mapper.xml  namespace属性写错了。


第一次写博客,语言组织不周,只想分享一个解决办法,望大家见谅。

感谢http://darkmasky.iteye.com/blog/1129828  博主给我的启发,非常感谢。

0 0