1. web.xml中classpath:和classpath*:  有什么区别?
  2. classpath:只会到你的class路径中查找找文件;
  3. classpath*:不仅包含class路径,还包括jar文件中(class路径)进行查找.
  4. 存放位置:
  5. 1:src下面
  6. 需要在web.xml中定义如下:
  7. <context-param>
  8. <param-name>contextConfigLocation</param-name>
  9. <param-value>classpath:applicationContext.xml</param-value>
  10. < /context-param>
  11. 2:WEB-INF下面
  12. 需要在web.xml中定义如下:
  13. <context-param>
  14. <param-name>contextConfigLocation</param-name>
  15. <param-value>WEB-INF/applicationContext*.xml</param-value>
  16. < /context-param>
  17. web.xml 通过contextConfigLocation配置spring 的方式
  18. SSI框架配置文件路径问题:
  19. struts2的 1个+N个 路径:src+src(可配置) 名称: struts.xml + N
  20. spring 的 1个 路径: src 名称: applicationContext.xml
  21. ibatis 的 1个+N个 路径: src+src(可配置) 名称: SqlMapConfig.xml + N
  22. 部署到tomcat后,src目录下的配置文件会和class文件一样,自动copy到应用的 classes目录下
  23. spring的 配置文件在启动时,加载的是web-info目录下的applicationContext.xml,
  24. 运行时使用的是web-info/classes目录下的applicationContext.xml。
  25. 配置web.xml使这2个路径一致:
  26. <context-param>
  27. <param-name>contextConfigLocation</param-name>
  28. <param-value>/WEB-INF/classes/applicationContext.xml</param-value>
  29. < /context-param>
  30. 多个配置文件的加载
  31. <context-param>
  32. <param-name>contextConfigLocation</param-name>
  33. <param-value>
  34. classpath*:conf/spring/applicationContext_core*.xml,
  35. classpath*:conf/spring/applicationContext_dict*.xml,
  36. classpath*:conf/spring/applicationContext_hibernate.xml,
  37. classpath*:conf/spring/applicationContext_staff*.xml,
  38. classpath*:conf/spring/applicationContext_security.xml
  39. classpath*:conf/spring/applicationContext_modules*.xml
  40. classpath*:conf/spring/applicationContext_cti*.xml
  41. classpath*:conf/spring/applicationContext_apm*.xml
  42. </param-value>
  43. </context-param>
  44. contextConfigLocation 参数定义了要装入的 Spring 配置文件。
  45. 首先与Spring相关的配置文件必须要以"applicationContext-"开头,要符合约定优于配置的思想,这样在效率上和出错率上都要好很多。
  46. 还有最好把所有Spring配置文件都放在一个统一的目录下,如果项目大了还可以在该目录下分模块建目录。这样程序看起来不会很乱。
  47. 在web.xml中的配置如下:
  48. Xml代码
  49. <context-param>
  50. < param-name>contextConfigLocation</param-name>
  51. < param-value>classpath*:**/applicationContext-*.xml</param-value>
  52. < /context-param>
  53. "**/"表示的是任意目录;
  54. "**/applicationContext-*.xml"表示任意目录下的以"applicationContext-"开头的XML文件。
  55. 你自己可以根据需要修改。最好把所有Spring配置文件都放在一个统一的目录下,如:
  56. <!-- Spring 的配置 -->
  57. <context-param>
  58. <param-name>contextConfigLocation</param-name>
  59. <param-value>classpath:/spring/applicationContext-*.xml</param-value>
  60. < /context-param>

applicationContext.xml存放的位置的更多相关文章

  1. applicationContext.xml的文件位置就可以有两种默认实现

    ContextLoaderListener的作用就是启动Web容器时,自动装配ApplicationContext的配置信息.因为它实现了ServletContextListener这个接口,在web ...

  2. applicationContext.xml文件放置位置不同而导致的jUnit测试的时候路径的不同

    如果applicationContext.xml文件放置在src下面的的时候使用jUint测试的时候编写的路径应该是这样的: @Test public void testFindByPage() { ...

  3. 转:applicationContext.xml文件放置位置不同而导致的jUnit测试的时候路径的不同

    如果applicationContext.xml文件放置在src下面的的时候使用jUint测试的时候编写的路径应该是这样的: @Test public void saveTest() { Applic ...

  4. Spring中,applicationContext.xml 配置文件在web.xml中的配置详解

    一.首先写一下代码结构. 二.再看web.xml中的配置情况. <?xml version="1.0" encoding="UTF-8"?> < ...

  5. spring-mvc.xml 和 application-context.xml的区别

    转自:https://www.cnblogs.com/binlin1987/p/7053016.html application-context.xml是全局的,应用于多个serverlet,配合li ...

  6. 【Spring】如何配置多个applicationContext.xml文件

    在web.xml中通过contextConfigLocation配置spring 开发Java Web程序,使用ssh架构时,默认情况下,Spring的配置文件applicationContext.x ...

  7. applicationContext.xml 配置文件的存放位置

    eb.xml中classpath:和classpath*:  有什么区别? classpath:只会到你的class路径中查找找文件; classpath*:不仅包含class路径,还包括jar文件中 ...

  8. [JavaEE] applicationContext.xml配置文件使用合集

    配置实例 – 1 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http ...

  9. applicationContext.xml中的使用${}是代表什么意思?

    在applicationContext.xml文件中,使用 ${xxx} 表示的是:调用某个变量,该变量的名称就是{xxx}里面的"xxx".   例如:在applicationC ...

随机推荐

  1. Shell中取时间格式方法

    Shell中取时间格式方法2007-09-13 15:35常用date的显示格式: date +%F //2007-03-06date +%Y%m%d//20070306 date +%T //23: ...

  2. Ecshop ajax 局部刷新购物车功能

    1.比如我们category.dwt 里有 <a href='flow.php'><SPAN id='cart_count_all'>{insert name='cart_in ...

  3. [转] TreeList 当前节点图标和背景色设置

    高原之上原文TreeList 选中节点时图标状态和背景色 // 给TreeList加SelectImage this.treelArea.SelectImageList = imglCustom; / ...

  4. MFC ListControl用法

    http://blog.csdn.net/lovton/article/details/6527208 1.建立一个对象m_LogList 步骤:在对话listcontrol控件右键点击添加变量-&g ...

  5. UITextView 相关知识点

    1.得到UITextView的高度 - (CGRect)contentSizeRectForTextView:(UITextView *)textView { [textView.layoutMana ...

  6. IOS color 颜色值比较

    /生成采样对照颜色(黑色) UIColor* sampleColor = [UIColor colorWithRed:(0/255.0f) green:(0/255.0f)  blue:(0/255. ...

  7. linux常用命令之--用户与用户组管理命令

    linux的用户与用户组管理命令 1.用户和群组 groupadd:用于添加新的组群 其命令格式如下: groupadd [-option] 群组名 常用参数: -g GID:指定创建群组的GID(G ...

  8. pycharm 源文件 编码格式

    pycharm 4.5.3 版本 修改项目的编码 按如下操作:菜单 File-Settings-Editor-File Encodings 将IDE Encoding 和 Project Encodi ...

  9. linux下安装pkg-config时遇到"glib-2.0>=2.16"的错

    解决办法 如报错提示所述,加上:--with-internal-glib 即 ./configure --with-internal-glib 参考链接: http://stackoverflow.c ...

  10. ehcache 的配置

    配置:一.在src目录下加入ehcache.xml: <cache name="SimplePageCachingFilter" maxElementsInMemory=&q ...