java - "classpath*"在 Spring MVC 项目中声明在哪里?

标签 java spring classpath keyword

我对此很好奇。

这个“classpath*”声明在哪里?

Follow 通常在 web.xml 中描述。

  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>
                classpath*:egovframework/springmvc/context-*.xml
            </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

我认为这个框架首先读取了 web.xml。但是它怎么知道这个关键字“classpath*:”呢?

提前感谢您的回答:D

最佳答案

我相信spring docs很好地描述类路径资源:

ClassPathResource

This class represents a resource which should be obtained from the classpath. This uses either the thread context class loader, a given class loader, or a given class for loading resources.

This Resource implementation supports resolution as java.io.File if the class path resource resides in the file system, but not for classpath resources which reside in a jar and have not been expanded (by the servlet engine, or whatever the environment is) to the filesystem. To address this the various Resource implementations always support resolution as a java.net.URL.

A ClassPathResource is created by Java code explicitly using the ClassPathResource constructor, but will often be created implicitly when you call an API method which takes a String argument which is meant to represent a path. For the latter case, a JavaBeans PropertyEditor will recognize the special prefix classpath:on the string path, and create a ClassPathResource in that case

关于java - "classpath*"在 Spring MVC 项目中声明在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25598077/

相关文章:

java - Glassfish War 部署 JAR 未加载

java - 使 Node JS 功能同步?在查询数据库之前发送json响应

java - Vaadin Spring Boot 找不到 npm 包

java - Spring Boot - 我的单元测试被跳过

java - 测试时使用 spring messagesource

java - 我在哪里放置 H2 触发器类?

java - 将文件夹包含到 jar 文件中

java - 按分数限制 SOLR 中的结果数量

java - SSL 握手失败 - Java 1.8

javascript - 如何在不更改缓存 list 的情况下使用 html 5 缓存 list 以编程方式更新页面服务器端?