您的位置:首页 > 其它

SSM框架---容器创建注入对象失败

2016-10-11 23:38 1751 查看
严重: 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的配置文件以及注解的错误。异常BeanCreationException: Error creating bean with name

 'bsxrServiceImpl':把真是的报错原因expected com.bj.dao.BsxrDao, but found com.bj.dao给隐藏了。

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

总结:

BeanCreationException: Error creating bean with name

 'bsxrServiceImpl':    原因之一就是  mapper动态代理  mapper.xml  namespace属性写错了。

感谢http://darkmasky.iteye.com/blog/1129828  博主给我的启发,非常感谢。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: