java - Why would IntelliJ be able to see my application context, but when I run my tests they can't see it? -
i had junit tests running fine. have stopped working, without change being done code itself. i'm assuming change must have happened configuration settings somewhere, cannot figure out problem lies.
i have test looks 1 below:
@runwith(springjunit4classrunner.class) @contextconfiguration(locations="classpath:applicationcontext.xml") public class mytests { @autowired mytestclass myclass @test public void myfirsttest() { // test code } } the directory structure looks this
- mypackage
- test
- java
- mytests
- java
- resources
- applicationcontext.xml
- test
the confusing thing of intellij understands context is. links in code, can see annotation of leaf , can click bring correct application context, , next bean autowired annotation can see little bean icon , when click it takes me definition inside application context. know it's there , can read. why can junit not see it? configuration have managed lose/change?
note: i'm trying both debug/run test through intellij.
edit: specific error is:
java.lang.illegalstateexception: failed load applicationcontext @ org.springframework.test.context.cacheawarecontextloaderdelegate.loadcontext(cacheawarecontextloaderdelegate.java:99) @ org.springframework.test.context.testcontext.getapplicationcontext(testcontext.java:122) @ org.springframework.test.context.web.servlettestexecutionlistener.setuprequestcontextifnecessary(servlettestexecutionlistener.java:105) @ org.springframework.test.context.web.servlettestexecutionlistener.preparetestinstance(servlettestexecutionlistener.java:74) @ org.springframework.test.context.testcontextmanager.preparetestinstance(testcontextmanager.java:312) @ org.springframework.test.context.junit4.springjunit4classrunner.createtest(springjunit4classrunner.java:211) @ org.springframework.test.context.junit4.springjunit4classrunner$1.runreflectivecall(springjunit4classrunner.java:288) @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:12) @ org.springframework.test.context.junit4.springjunit4classrunner.methodblock(springjunit4classrunner.java:284) @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:231) @ org.springframework.test.context.junit4.springjunit4classrunner.runchild(springjunit4classrunner.java:88) @ org.junit.runners.parentrunner$3.run(parentrunner.java:290) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:71) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:288) @ org.junit.runners.parentrunner.access$000(parentrunner.java:58) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:268) @ org.springframework.test.context.junit4.statements.runbeforetestclasscallbacks.evaluate(runbeforetestclasscallbacks.java:61) @ org.springframework.test.context.junit4.statements.runaftertestclasscallbacks.evaluate(runaftertestclasscallbacks.java:71) @ org.junit.runners.parentrunner.run(parentrunner.java:363) @ org.springframework.test.context.junit4.springjunit4classrunner.run(springjunit4classrunner.java:174) @ org.junit.runner.junitcore.run(junitcore.java:137) @ com.intellij.junit4.junit4ideatestrunner.startrunnerwithargs(junit4ideatestrunner.java:74) @ com.intellij.rt.execution.junit.junitstarter.preparestreamsandstart(junitstarter.java:211) @ com.intellij.rt.execution.junit.junitstarter.main(junitstarter.java:67) @ sun.reflect.nativemethodaccessorimpl.invoke0(native method) @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:57) @ com.intellij.rt.execution.application.appmain.main(appmain.java:134) caused by: org.springframework.beans.factory.beandefinitionstoreexception: ioexception parsing xml document class path resource [dataapplicationcontext.xml]; nested exception java.io.filenotfoundexception: class path resource [dataapplicationcontext.xml] cannot opened because not exist @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbeandefinitions(xmlbeandefinitionreader.java:341) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbeandefinitions(xmlbeandefinitionreader.java:302) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:174) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:209) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:180) @ org.springframework.beans.factory.support.abstractbeandefinitionreader.loadbeandefinitions(abstractbeandefinitionreader.java:243) @ org.springframework.test.context.support.abstractgenericcontextloader.loadbeandefinitions(abstractgenericcontextloader.java:233) @ org.springframework.test.context.support.abstractgenericcontextloader.loadcontext(abstractgenericcontextloader.java:117) @ org.springframework.test.context.support.abstractgenericcontextloader.loadcontext(abstractgenericcontextloader.java:60) @ org.springframework.test.context.support.abstractdelegatingsmartcontextloader.delegateloading(abstractdelegatingsmartcontextloader.java:100) @ org.springframework.test.context.support.abstractdelegatingsmartcontextloader.loadcontext(abstractdelegatingsmartcontextloader.java:248) @ org.springframework.test.context.cacheawarecontextloaderdelegate.loadcontextinternal(cacheawarecontextloaderdelegate.java:64) @ org.springframework.test.context.cacheawarecontextloaderdelegate.loadcontext(cacheawarecontextloaderdelegate.java:91) ... 28 more caused by: java.io.filenotfoundexception: class path resource [dataapplicationcontext.xml] cannot opened because not exist @ org.springframework.core.io.classpathresource.getinputstream(classpathresource.java:157) @ org.springframework.beans.factory.xml.xmlbeandefinitionreader.loadbeandefinitions(xmlbeandefinitionreader.java:328) ... 40 more
just try this:
@contextconfiguration(locations="classpath:applicationcontext.xml") change to:
@contextconfiguration(locations={"classpath:**/applicationcontext.xml"})
Comments
Post a Comment