gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 05:18:42 25 4
gpt4 key购买 nike

我对此很好奇。

这个“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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com