请稍等 ...
×

采纳答案成功!

向帮助你的同学说点啥吧!感谢那些助人为乐的人

报错! 2-7 AreaDaoTest配置和测试问题

老师您好,我在之前的课程中一直发现并更正各类语法,拼写错误,走到2-7AreaDaoTest配置时,我发现我的assertEquals imports选项和老师有了不同,只有org.junit.Assert.assertEquals这一个import选项,我暂时保存并跟着进度run as junit。报错的内容如下:如图所示,和教程的imports选项有异
严重: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@6be46e8f] to prepare test instance [com.imooc.o2o.dao.AreaDaoTest@2b2948e2]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:124)
at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:83)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:230)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.createTest(SpringJUnit4ClassRunner.java:228)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner$1.runReflectiveCall(SpringJUnit4ClassRunner.java:287)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.methodBlock(SpringJUnit4ClassRunner.java:289)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:247)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:94)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:191)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:538)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:760)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:206)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring/spring-dao.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring/spring-dao.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:344)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:304)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:181)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:217)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:252)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadBeanDefinitions(AbstractGenericContextLoader.java:257)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:124)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.delegateLoading(AbstractDelegatingSmartContextLoader.java:108)
at org.springframework.test.context.support.AbstractDelegatingSmartContextLoader.loadContext(AbstractDelegatingSmartContextLoader.java:251)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:98)
at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:116)
… 25 more
Caused by: java.io.FileNotFoundException: class path resource [spring/spring-dao.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:172)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:330)
… 37 more

我还不会看报错解决问题,请教老师**Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@6be46e8f] to prepare test instance [com.imooc.o2o.dao.AreaDaoTest@2b2948e2]**这句指出了什么问题,要怎么解决呢?谢谢老师
-----------------------------------------------分割----------------------------------------
今天晚上打开电脑,发现原有的工程开始报错,表现为xml文件第一行打红叉,称referenced file contains errors……,但是百度上说这是eclipse抽风,clean文件或者剪切粘贴一遍就好了。我照做后确实消除了红叉,这算我配置有误吗?

正在回答 回答被采纳积分+3

1回答

翔仔 2019-04-08 23:41:29

同学好,感觉同学maven和eclipse配置得有问题,需要将你本地已经安装好的maven和你的eclipse连通,具体需要参考下图

https://img1.sycdn.imooc.com//szimg/5cab6b130001989014041066.jpg

设置好之后,去到截图里的repository路径,也就是maven的repository路径下把所有jar清空,之后update maven project, clean project,rebuild project试试。

然后上面的问题,想要使用assertEquals,必须要这样引入

import static org.junit.Assert.assertEquals;

然后我看同学这里报错

FileNotFoundException: class path resource [spring/spring-dao.xml] cannot be opened because it does not exist,说的是同学的spring-dao.xml文件不存在呢,请仔细看看src/main/resources/spring下面是否有这个文件。

按照上面说的一步步排查哈

1 回复 有任何疑惑可以回复我~
  • 提问者 端木云 #1
    感谢老师深夜回复我。实际上,我正在跟着老师的步骤一步一步做还有半个月就要交的毕设。我是零基础,现在每天都花至少8-10小时学习各种相关知识,感到非常迷茫。就连我的eclipse和maven mysql都是已经工作的同学帮我远程配置的……目前就卡在assertEquals引入设置这一步,看到老师说配置出了问题直接眼前一黑~老师您对我这种:时间紧 任务重 “困难不少”的学生有什么建议吗……一直提基础问题挺不好意思的
    回复 有任何疑惑可以回复我~ 2019-04-09 00:20:58
  • 翔仔 回复 提问者 端木云 #2
    建议同学一定要在被虐中培养起独立解决问题的能力,这个在以后的工作中是必备的,毕竟后续没有人能帮得到同学,同时在压力下学习,在困难中学习效果是最好的,也最能成长,不然一帆风顺是很难成长的。建议同学加入到群里,跟别的同学尤其是进度超前的小伙伴多请教请教,这样也能获得实时反馈。java很多时候都是在解决配置或者环境的问题,同学遇到此类问题,可以把cause附近的语句,自己能看得懂的语句贴百度上,一般都会有答案。0基础的话建议同学还是花一两天时间入门,看看spring入门知识,maven以及mysql入门知识,否则会遇到各种各样难以解决的问题。看的资料可以随意,要那种菜鸟入门容易理解的即可,后续再深入学习
    回复 有任何疑惑可以回复我~ 2019-04-09 00:29:02
  • 提问者 端木云 #3
    而且清空jar……我不明白,所有手动删除了repository下的所有文件(有备份),然后重新进入eclipse,这次进入的很缓慢。我就updating maven project了,但是没有在quick access下找到“clean project”和“rebuild project”,倒是有clean clean up rebuild java index之类的选项。这一步我没有继续做下去,暂且等update之后看结果吧。希望老师能把我拉进qq群组之类有同学可以请教的地方,这样我也好跟同学们讨论请教。qq:1611965866. 晚安
    回复 有任何疑惑可以回复我~ 2019-04-09 01:20:52
问题已解决,确定采纳
还有疑问,暂不采纳
意见反馈 帮助中心 APP下载
官方微信