与异常的斗争_Could not open ServletContext resource [/mybatis/mainCon.xml]

出现的异常 : org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'orderDaoImpl': Unsatisfied dependency expressed through method 'setOrderDao' parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'orderDao' defined in file [C:\Users\idaepad\.IntelliJIdea2018.1\system\tomcat\Unnamed_level2_ssm2\work\Catalina\localhost\_\WEB-INF\classes\com\theangryz\dao\OrderDao.class]: Cannot resolve reference to bean 'sqlSessionFactory' while setting bean property 'sqlSessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [spring/application.xml]: Invocation of init method failed; nested exception is java.io.FileNotFoundException: Could not open ServletContext resource [/mybatis/mainCon.xml]

出现异常的运行环境 : IDEA maven进行ssm项目的时候,启动服务器抛出该异常.

该异常耗费大量时间的原因 : 在出现异常时自己总是如同无头苍蝇吧各种尝试, 而不是静下心来仔细分析异常(英文差也得硬着头皮看,况且大致意思完全没有问题).

解决办法 : 最终原因异常信息已经给出-无法打开ServletContext资源 /mybatis/mainCon.xml, 所以是mybatis配置文件的打开出现了问题. 在github中找到了答案: spring配置文件路径必须添加classPath: 前缀, 不然找不到.

优化 : 在遇到异常时更应该首先仔细分析异常, 而不是想着先Google,首先自己分析问题,之后再google.

posted @ 2019-12-05 10:05  gogoog  阅读(865)  评论(0编辑  收藏  举报