Failed to load ApplicationContext from Unit Test: FileNotFound

前端 未结 9 1045
夕颜
夕颜 2021-02-01 14:44

I am creating a Maven Spring project, which includes MVC, Data and Security. My Spring applicationContext-*.xml files are located at \\src\\main\\resources\\spring\\

My

相关标签:
9条回答
  • 2021-02-01 15:12

    Try with the relative path using *

      @ContextConfiguration(locations = {
    "classpath*:spring/applicationContext.xml",
    "classpath*:spring/applicationContext-jpa.xml",
    "classpath*:spring/applicationContext-security.xml" })
    

    If not look if your xml are really on resources/spring/.

    Finally try just on without location

     @ContextConfiguration({"classpath*:spring/applicationContext.xml"})
    

    The other error that you´re showing is because you have this tag duplicated on applicationContext.xml and applicationContext-security.xml

     Duplicate <global-method-security>
    
    0 讨论(0)
  • 2021-02-01 15:17

    I added the spring folder to the build path and, after clean&build, it worked.

    0 讨论(0)
  • 2021-02-01 15:18

    Give the below

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

    And in pom.xml give the following plugin:

    <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-surefire-plugin</artifactId>
       <version>2.20.1</version>
    <configuration>
        <additionalClasspathElements>
           <additionalClasspathElement>${basedir}/src/test/resources</additionalClasspathElement>
        </additionalClasspathElements>
    </configuration>
    

    0 讨论(0)
提交回复
热议问题