Java Project: Failed to load ApplicationContext

后端 未结 3 1643
情深已故
情深已故 2020-12-28 12:55

I have a Java Project in which I am writing a simple JUNIT test case. I have copied the applicatinoContext.xml file into the root java source directory. I\'ve tried it wit

3条回答
  •  南笙
    南笙 (楼主)
    2020-12-28 13:51

    Looks like you are using maven (src/main/java). In this case put the applicationContext.xml file in the src/main/resources directory. It will be copied in the classpath directory and you should be able to access it with

    @ContextConfiguration("/applicationContext.xml")
    

    From the Spring-Documentation: A plain path, for example "context.xml", will be treated as a classpath resource from the same package in which the test class is defined. A path starting with a slash is treated as a fully qualified classpath location, for example "/org/example/config.xml".

    So it's important that you add the slash when referencing the file in the root directory of the classpath.

    If you work with the absolute file path you have to use 'file:C:...' (if I understand the documentation correctly).

提交回复
热议问题