原文链接: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. 测试覆盖率工具:EclEmma

    测试覆盖率工具:EclEmma 2016-08-26 目录 1 测试覆盖率实现技术2 EclEmma介绍3 EclEmma测试覆盖率指标4 EclEmma安装5 示例项目介绍  5.1 创建项目  5 ...

  2. 使用ActivityGroup需要注意的地方

    Group里面的所有“孩子Activity”不能直接调用finish(),只能等ActivityGroup调用它自己的finish()后,会自动调用所有“孩子Activity”的finish().

  3. chrome调试手机webview中页面

    http://blog.csdn.net/freshlover/article/details/42528643 注: 1. 可以调试真机上页面(USB连接)和虚拟机上页面 2. 手机系统需要4.4+ ...

  4. hdoj:2040

    #include <iostream> #include <vector> using namespace std; vector<long> yueShu(lon ...

  5. android:onClick都做了什么

    同步发表于 http://avenwu.net/viewinject/2015/01/28/android_onclick/ 相信大家都知道在layout里面可以给view写android:onCli ...

  6. Mysql系列三:Centos6下安装Mysql和Mysql主从复制的搭建

    一.Centos6下安装Mysql 检测下系统有没有自带的mysql:yum list installed | grep mysql, 如果已经有的话执行命令yum -y remove mysql-l ...

  7. Kubernetes集群部署之一系统环境初始化

    安装版本: centos version: 7.4 docker version: 18.03.1-ce kubectl version: v1.10.1 etcdctl version: 3.2.1 ...

  8. Dapper Extensions Change Schema

    Dapper Extensions Change Schema You can use the AutoClassMapper to assign a new schema to your model ...

  9. DedeCMS中channelartlist自增参数global.itemindex

    在 dede:channelartlist 标签下,使用: {dede:global.itemindex runphp='yes'} {/dede:global.itemindex} dede:cha ...

  10. Linux驱动技术(二) _访问I/O内存

    ARM是对内存空间和IO空间统一编址的,所以,通过读写SFR来控制硬件也就变成了通过读写相应的SFR地址来控制硬件.这部分地址也被称为I/O内存.x86中对I/O地址和内存地址是分开编址的,这样的IO ...