spring - @ContextConfiguration fail to load config file in src/test/resources

烈酒焚心 提交于 2019-12-03 01:16:15

To be precise, it's the content of the test output directory (target/test-classes) that is on the class path, not src/test/resources. But resources under src/test/resources are copied to the test output directory by the resources:testResources goal (which is bound by default to the process-test-resources phase).

Having that said, your code looks fine and resources for the test source code should have been copied either by your IDE or by Maven when running tests and should thus be available on the class path. So there must be something else wrong. I can see that your class is a base class for integration tests. Did you configure anything fancy in your pom? Can you show it?

prashant thakre

Try by using * so that it can search to your classpath

@ContextConfiguration(locations={"classpath*:applicationContext.xml"})
Jesse Webb

There is a reported bug with using the spring-test dependency (includes SpringJUnit4ClassRunner) with versions of JUnit > 4.4.

If you are using a version of JUnit newer than 4.4, trying moving that down to 4.4 and see if it solves your problem.

your application context must be included in classpath and put * :

@ContextConfiguration(locations = { "classpath:*/application-context.xml" })

You seem to be using maven, and trying to run the tests from within eclipse. Check the buil folder (target/test-classes/) for applicationContext.xml. If it is not there, you'd have to build first.

I think i have a simillar problem, I found out that my application-context.xml was not on target/test-classes/ neighter on src/test/resources

Rupali

If you are using Maven and running test cases from eclipse, project right click > Maven > maven update (ALTF5)might work for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!