org.springframework.beans.factory.BeanCreationException

org.springframework.beans.factory.BeanCreationException

这些天,在学SSM整合(Spring、SpringMvc、MyBatis)。学习的过程中,遇到了这个问题,可能是太久没做网站开发的原因,看着一连串的报错,有些懵逼。幸得大学室友相助,找到了报错的原因,今在此留下笔记,望有助于后面的学者。

1.相关博客

首先,我通过查找相关资料,找到了这位博主关于这个问题的介绍。该博主表明,BeanCreationException可能发生的原因包括:

  • 没有对Bean加注解。
  • 注解导错了包。
  • 选择了错误的自动注入方式。
    博客链接如下:
    [博客链接] [https://blog.csdn.net/qq_35246620/article/details/70216023]
    除此之外, 还有博主表明,Web.xml中的相关配置,如过滤器配置错误,也可能会产生这个错误。事实表明,我的Web.xml确实有问题,改正之后,这个问题并没有彻底解决。

2.我的解决方案

通过我舍友对错误日志的分析,首先定位到了错误的位置为EmployeeMapper.xml有问题。
日志相关内容:

lineNumber: 18; columnNumber: 75; 需要属性 "property", 并且必须为元素类型 "association" 指定该属性。

由上面日志可以得出,出错的行数为18行,可能出现的问题未property单词拼写错误或者association单词拼写错误。果不其然,我的property属性拼错了。修改之后,错误得到解决。

3.相关日志信息

ERROR 01-05 13:50:44,633 Context initialization failed  (ContextLoader.java:318) 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'employeeServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.dengdan.ssm.mapper.EmployeeMapper com.dengdan.ssm.service.EmployeeServiceImpl.employeeMapper; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'employeeMapper' defined in file [D:\myeclipseData1\.metadata\.me_tcat7\me-webapps\ssmExample\WEB-INF\classes\com\dengdan\ssm\mapper\EmployeeMapper.class]: Unsatisfied dependency expressed through bean property 'sqlSessionFactory': : Error creating bean with name 'org.mybatis.spring.SqlSessionFactoryBean#0' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\myeclipseData1\.metadata\.me_tcat7\me-webapps\ssmExample\WEB-INF\classes\mybatis\mapper\EmployeeMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 18; columnNumber: 75; 需要属性 "property", 并且必须为元素类型 "association" 指定该属性。; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.mybatis.spring.SqlSessionFactoryBean#0' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [D:\myeclipseData1\.metadata\.me_tcat7\me-webapps\ssmExample\WEB-INF\classes\mybatis\mapper\EmployeeMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error creating document instance.  Cause: org.xml.sax.SAXParseException; lineNumber: 18; columnNumber: 75; 需要属性 "property", 并且必须为元素类型 "association" 指定该属性。
	at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
	at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:700)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482)
	at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:381)
	at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:293)
	at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106)
	at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4994)
	at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5492)
	at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
	at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
	at java.util.concurrent.FutureTask.run(FutureTask.java:262)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at java.lang.Thread.run(Thread.java:744)

4.反思

编写代码时,一定要细心,追求高速的同时,更需注重高效。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值