`

Java web工程web.xml 配置中classpath: 与classpath*:的区别

 
阅读更多
首先 classpath是指 WEB-INF文件夹下的classes目录

解释classes含义:
1.存放各种资源配置文件 eg.init.properties log4j.properties struts.xml
2.存放模板文件 eg.actionerror.ftl
3.存放class文件 对应的是项目开发时的src目录编译文件
总结:这是一个定位资源的入口

如果你知道开发过程中有这么一句话:惯例大于配置 那么也许你会改变你的想法

对于第二个问题
这个涉及的是lib和classes下文件访问优先级的问题: lib>classes
对于性能的影响应该不在这个范畴

classpath 和 classpath* 区别:
classpath:只会到你的class路径中查找找文件;
classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找.

<param-value>classpath:applicationContext-*.xml</param-value> 

或者引用其子目录下的文件,如

<param-value>classpath:context/conf/controller.xml</param-value> 


classpath*的使用:当项目中有多个classpath路径,并同时加载多个classpath路径下(此种情况多数不会遇到)的文件,*就发挥了作用,如果不加*,则表示仅仅加载第一个classpath路径,代码片段:
Java代码  收藏代码
<param-value>classpath*:context/conf/controller*.xml</param-value> 


另外:
"**/" 表示的是任意目录;
"**/applicationContext-*.xml"  表示任意目录下的以"applicationContext-"开头的XML文件。 
程序部署到tomcat后,src目录下的配置文件会和class文件一样,自动copy到应用的 WEB-INF/classes目录下
classpath:与classpath*:的区别在于,

前者只会从第一个classpath中加载,而
后者会从所有的classpath中加载 

如果要加载的资源,
不在当前ClassLoader的路径里,那么用classpath:前缀是找不到的,
这种情况下就需要使用classpath*:前缀

在多个classpath中存在同名资源,都需要加载,
那么用classpath:只会加载第一个,这种情况下也需要用classpath*:前缀

注意:
用classpath*:需要遍历所有的classpath,所以加载速度是很慢的,因此,在规划的时候,应该尽可能规划好资源文件所在的路径,尽量避免使用classpath*。


from : http://perfy315.iteye.com/blog/2009258
分享到:
评论

相关推荐

    springboot学习

    mapper-locations: classpath:/mapper/*Mapper.xml JSP 配置: mvc: view: prefix: / suffix: .jsp 四、MyBatis 简介 MyBatis 是一个基于 Java 的持久层框架,提供了对数据库的交互操作。MyBatis 提供了一个...

    Javascript+tomcat+ssl.docx

    2. Java 环境变量配置:在 /etc/profile 文件中添加环境变量,包括 JAVA_HOME、CLASSPATH 和 PATH 变量,然后重新加载环境变量文件。 3. Java 版本测试:使用 `java -version` 命令来测试 Java 版本是否正确安装。 ...

    asm5.0.jar

    2013-08-12 14:33:37.672:... Add CGLIB to your classpath.:java.lang.IncompatibleClassChangeError: class net.sf.cglib.core.DebuggingClassWriter has interface org.objectweb.asm.ClassVisitor as super class

    javaservlet连接mysql数据库可用.pdf

    在使用 Java Servlet 连接 MySQL 数据库之前,需要配置 Tomcat 服务器和 web.xml 文件。 1. 配置 server.xml 文件:在 Tomcat 服务器的 conf 目录下,添加 Resource 标签,配置数据库连接池参数。 2. 配置 web.xml ...

    maven相关资料

    ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:/*.xml"); 二、ClassPathXmlApplicationContext[只能读放在web-info/classes目录下的配置文件]和FileSystemXmlApplicationContext的区别 ...

    基于java的企业级应用开发:Spring的核心容器.ppt

    通常会使用ContextLoaderListener来实现,此种方式只需要在web.xml中添加如下代码: &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt; classpath:spring/applicationContext.xml ...

    springweb3.0MVC注解(附实例)

    web.xml 中定义了一个名为 annomvc 的 Spring MVC 模块,按照 Spring MVC 的契约,需要在 WEB-INF/annomvc-servlet.xml 配置文件中定义 Spring MVC 模块的具体配置。annomvc-servlet.xml 的配置内容如下所示: &lt;?xml...

    一套英文Java笔试题面试题.doc

    3.please explain about web.xml 4.please explian about mainifest.mf 5.what technology are used in J2EE platfrom.please list and explain concisely. 6.please explain the relationship between classpath ...

    jdk5.5+tomcat5.5 环境配置

    jdk5.5+tomcat5.5 环境配置是 Java 开发中常用的服务器配置,下面将详细介绍其配置过程。 一、下载和安装 jdk 和 tomcat 首先,需要下载最新的 jdk 和 tomcat 软件包。目前,最新的 jdk 版本为 1.5,tomcat 版本为...

    ssh框架错误总结

    解决方法:在web.xml文件中添加struts-config.xml的配置信息,确保struts-config.xml文件正确配置。 五、JSTL相关错误 如果缺少JSTL相关的JAR包和web.xml配置,将导致org.apache.jasper.JasperException: The ...

    DOS命令使用方法(超全).

    &lt;param-value&gt;classpath*:applicationContext-*.xml &lt;!-- 这是spring 监听 --&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener &lt;!-- 利用spring监听 编码设置 --&gt; ...

    基于java的企业级应用开发:Spring MVC的核心类和注解.ppt

    在使用时,只需将其配置在项目的web.xml文件中,其配置代码如下: &lt;servlet&gt; &lt;servlet-name&gt;springmvc&lt;/servlet-name&gt; &lt;servlet-class&gt; org.springframework.web.servlet.DispatcherServlet &lt;/servlet-class&gt; ...

    Spring中ApplicationContext加载机制

    配置非常简单,在 web.xml 中增加相应的配置信息。例如,使用 ContextLoaderListener 可以增加以下配置信息: ```xml org.springframework.web.context.ContextLoaderListener ``` 或者,使用 ...

    17 、各种spring项目建立1

    在 web.xml 文件中,我们需要配置 Spring 环境的相关信息。下面是 web.xml 文件的示例代码: ```xml &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ...

    生活轨迹SSH服务端

    -- &lt;param-value&gt;/WEB-INF/applicationContext-*.xml,classpath*:applicationContext-*.xml&lt;/param-value&gt; --&gt; &lt;param-value&gt;classpath:beans.xml &lt;filter-name&gt;struts2 &lt;filter-class&gt;org.apache.struts2...

    Struts2+Spring3+MyBatis3完整实例

    网上的东西好大多都不能直接用,自己结合网上资料做了一个Struts2+Spring3+MyBatis3的测试工程,JUnit测试用例和WEB服务。 内涵完整jar包,解压直接可用,包括一个表文件。 Eclipse3.2+Tomcat/5.5+jdk1.5.0_17 - ...

    Spring-Reference_zh_CN(Spring中文参考手册)

    12.5.1. iBATIS 1.x和2.x的概览与区别 12.5.2. iBATIS SQL Maps 1.x 12.5.2.1. 创建SqlMap 12.5.2.2. 使用 SqlMapTemplate 和 SqlMapDaoSupport 12.5.3. iBATIS SQL Maps 2.x 12.5.3.1. 创建SqlMapClient 12.5.3.2....

    jdk 与 tomcat 环境变量配置大全

    jdk 与 tomcat 环境变量配置大全 jdk 和 tomcat 环境变量配置是 Java 编程的基础,正确的配置是保证 Java 应用程序运行的前提。本文将详细介绍 jdk 和 tomcat 环境变量配置的步骤和注意事项。 一、下载 jdk 和 ...

    soccerLeague

    ............\....\...\.......\web.xml ............\....\web.war ............\etc ............\...\web ............\...\...\catalog.txt ............\...\...\web.xml ............\lib ..............

    Tomcat及其插件apache-tomcat-5.5.26-admin.zip的安装

    解压Administration Web Application,假设目录为F:\ apache-tomcat-5.5.25 把F:\ apache-tomcat-5.5.25 \server\webapps下面的admin文件夹copy到D:\apache-tomcat-5.5.25\server\webapps下面; 把F:\ apache-...

Global site tag (gtag.js) - Google Analytics