【问题标题】:Spring MVC @ContextConfigurationSpring MVC @ContextConfiguration
【发布时间】:2016-04-27 09:07:29
【问题描述】:

我正在学习 Java 和 Spring MVC。我找到了这段代码:

@ContextConfiguration(locations = { "classpath: com/myname/spring/junit-context.xml" })

我了解 com/myname/spring/junit-context.xml 是相对路径。 我的问题是:在 Web 应用程序的上下文中它与 TO 相关的是什么?

【问题讨论】:

    标签: java spring-mvc


    【解决方案1】:

    它是相对于类路径的(这就是它以类路径为前缀的原因)。您的类路径中可以有多个文件夹和 jar,Spring 将在所有文件夹和 jar 中搜索资源文件。

    【讨论】:

      【解决方案2】:
      @ContextConfiguration(locations = {
          "file:src/main/webapp/WEB-INF/spring/root-context.xml",
          "file:src/main/webapp/WEB-INF/spring/security-context.xml",
          "file:src/main/webapp/WEB-INF/spring/appServlet/servlet-context.xml" })
      

      webapp -> WEB-INF -> spring -> ContextConfiguration 文件名


      com/myname/spring

      com -> myname-> spring-> 文件名

      只是文件夹结构

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-06-28
        • 2015-08-16
        • 2016-04-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-01-18
        相关资源
        最近更新 更多