原文链接:web.xml 配置中classpath: 与classpath*:的区别

引用自:http://blog.csdn.net/wxwzy738/article/details/16983935

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

classpath 和 classpath* 区别

classpath:只会到你指定的class路径中查找文件;

classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找.

举个简单的例子,在我的web.xml中是这么定义的:classpath*:META-INF/spring/application-context.xml

那么在META-INF/spring这个文件夹底下的所有application-context.xml都会被加载到上下文中,这些包括 META-INF/spring文件夹底下的 application-context.xml,META-INF/spring的子文件夹的application-context.xml以及 jar中的application-context.xml。

如果我在web.xml中定义的是:classpath:META-INF/spring/application-context.xml

那么只有META-INF/spring底下的application-context.xml会被加载到上下文中。

项目实践中用的比较多就是在web.xml文件中配置spring监听器,让它读取*.xml文件,加载其中的bean.

举例如下

首先:在ssh框架搭建好之后,在web.xml文件中进行如下配置

<!--系统自动加载文件 -->

这里使用的是classpath*:的形式

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:ssh2-*.xml</param-value>
</context-param>

<!--配置spring的context监听器  -->

<listener>

<listener-class>org.springframework.web.context.ContextLoaderListener

</listener-class>

</listener>

在项目的.classpath文件中有如下的配置

补充:

1.)关于.classpath文件的查看可以去项目存放的位置(workplace)下查看,也可以在eclipse中navigator视图中进行查看

2.)navigator视图是在window---->show view----->other------>navigator中可以找到.

<?xml version="1.0" encoding="UTF-8"?>
<classpath>

<!--系统默认的class文件加载路径,不能够删除-->
<classpathentry kind="src" path="src"/>

<!--自己新添加的class文件加载路径-->
<!--<classpathentry kind="src" path="config"/>-->

这里可以添加classpath的路径,例如我的配置文件路径时放在了与src同级的目录下,你也可以指定自己的文件存放路径.

项目启动时候,系统会依据.classpath文件中指定的src的路径依次查找所要加载的配置文件。并加载其中的bean.

转:web.xml 配置中classpath: 与classpath*:的区别的更多相关文章

  1. web.xml配置参数context-param和init-param的区别

    web.xml配置参数context-param和init-param的区别 (2009-04-13 10:29:01) 转载▼ 标签: 杂谈 分类: JavaEE web.xml里面可以定义两种参数 ...

  2. web.xml 配置中classpath: 与classpath*:的区别

    首先 classpath是指 WEB-INF文件夹下的classes目录 解释classes含义: 1.存放各种资源配置文件 eg.init.properties log4j.properties s ...

  3. web.xml 配置中classpath: 与classpath*:的区别——(十一)

    首先 classpath是指 WEB-INF文件夹下的classes目录 解释classes含义: 1.存放各种资源配置文件 eg.init.properties log4j.properties s ...

  4. web.xml配置中的log4jRefreshInterval讲解

    采用spring框架的项目如何使用log4j在spring中使用log4j,有些方便的地方, 1.动态的改变记录级别和策略,即修改log4j.properties,不需要重启web应用,这需要在web ...

  5. web.xml配置中的log4jRefreshInterval

    采用spring框架的项目如何使用log4j在spring中使用log4j,有些方便的地方, 1.动态的改变记录级别和策略,即修改log4j.properties,不需要重启web应用,这需要在web ...

  6. 关于web.xml配置中的<url-pattern>

    标签<url-pattern> <url-pattern>是我们用Servlet做Web项目时需要经常配置的标签,例: <servlet><servlet-n ...

  7. web.xml配置中的 文件类型<mime-mapping>

    <mime-mapping> <extension>doc</extension> <mime-type>application/msword</ ...

  8. WEB项目web.xml文件中classpath: 跟classpath*:使用的区别

    引用一篇很不错的文章:http://blog.csdn.net/wxwzy738/article/details/16983935 首先 classpath是指 WEB-INF文件夹下的classes ...

  9. ssm框架中,项目启动过程以及web.xml配置详解

    原文:https://blog.csdn.net/qq_35571554/article/details/82385838 本篇主要在基于SSM的框架,深入讲解web.xml的配置 web.xml   ...

随机推荐

  1. 项目在iOS11上遇到的小问题

    ​iOS11正式版出了这么久了,在忙完新版本开发,写下在iOS11上的一些小问题. 1  App图标不显示 现象:升级到iOS11系统下自己的项目桌面app图标不见了 出现这种情况我还以为自己手动删除 ...

  2. linux每日命令(25):Linux文件类型与扩展名

    Linux文件类型和Linux文件的文件名所代表的意义是两个不同的概念.我们通过一般应用程序而创建的比如file.txt.file.tar.gz ,这些文件虽然要用不同的程序来打开,但放在Linux文 ...

  3. openfire群消息投递

  4. oracle 回收表空间的数据文件大小

    查看表空间的使用情况: " "used MB",b.bytes "free MB", ,) "percent_used" from ...

  5. 使用C#+Linq+SQL快速开发业务

    C#开发桌面程序的效率确实很高,今天就来总结下如何使用C#+Linq+SQL快速开发一个新的业务系统. Linq是微软官方的轻量级的ORM工具,使用它结合SQL可以快速的生成实体类,再通过Linq操作 ...

  6. Halcon 2D测量

    * This program shows how to detect the edges of a diamond * with subpixel accuracy and calculate the ...

  7. MongoDB随笔3:使用索引

    创建索引的语句很简单. 1.单键索引的创建:db.test.ensureIndex({name:1},{name:'index_name'}) 2.复合索引的创建:db.test.ensureInde ...

  8. Dapper的基本使用,Insert、Update、Select、Delete

    简介 Dapper是.NET下一个micro的ORM,它和Entity Framework或Nhibnate不同,属于轻量级的,并且是半自动的.也就是说实体类都要自己写.它没有复杂的配置文件,一个单文 ...

  9. 【转】QT Graphics-View官方介绍(中文翻译)

    一.GraphicsView框架简介 QT4.2开始引入了Graphics View框架用来取代QT3中的Canvas模块,并作出了改进,Graphics View框架实现了模型-视图结构的图形管理, ...

  10. [Hinton] Neural Networks for Machine Learning - Basic

    Link: Neural Networks for Machine Learning - 多伦多大学 Link: Hinton的CSC321课程笔记1 Link: Hinton的CSC321课程笔记2 ...