Spring中的WebAppRootListener
来源:互联网 发布:java酒店管理系统 编辑:程序博客网 时间:2024/05/21 23:31
WebAppRootListener
这个listener的作用就是监听web.xml中的配置param-name为webAppRootKey的值:
<context-param> <param-name>webAppRootKey</param-name> <param-value>myroot</param-value></context-param>
然后配置一个然后配置一个监听器:
<listener> <listener-class> org.springframework.web.util.WebAppRootListener </listener-class></listener>
这个监听器会在web上下文初始化的时候,cs调用webUtil的对应方法,首先获取根传递进来的servletContext得到物理路径,String path=servletContext.getRealPath("/"); 然后找到context-param的webAooRootKey对应的param-value,把param-value的值作为key,上面配置的是"myroot", 接着执行System.setProperty("myroot",path)。这样在web中就可以使用System.getProperty("myroot")来获取系统的绝对路径。
注:
1)如果只配置了监听器,没有配置webAppRootKey, 默认wenAppRootKey对应的param-value的值为webapp.root。
2)上面得到系统路径是Spring的做法,和平时自己采用的方法基本一致,都是写一个监听器,然后得到物理路径后手动放入System中,一般还会在这个监听器中加载配置文件,获取配置文件的值。
0 0
- Spring中的WebAppRootListener
- Spring中的WebAppRootListener
- Spring中的WebAppRootListener
- Spring中的WebAppRootListener
- Spring 中WebAppRootListener的误解
- servlet3.0 contextLoadListener和WebAppRootListener
- java.lang.ClassNotFoundException: org.springframework.web.util.WebAppRootListener
- WebAppRootListener使用的过程中遇到的问题
- [Spring]Spring中的事务管理
- Spring 中的事务处理
- Spring中的ProxyFactoryBean
- Spring中的getBean
- Spring中的Bean
- spring中的问题
- Spring 中的 AOP
- Spring中的名词概念
- Spring中的WebApplicationContext
- Spring中的数据绑定
- JDK中所包含的设计模式
- Linux socket编程之阻塞套接字和非阻塞套接字
- 第8篇.布局、控件等零散记录相关
- Binder学习指南
- spring data jpa 懒加载异常处理记录
- Spring中的WebAppRootListener
- C++对象的动态建立和释放
- NATAPP 之 测试利器
- 《Python编程》笔记(五)
- 轻松理解 Android Binder,只需要读这一篇
- Linux中Kill如何进程 总结
- 无webshell的UDF提权
- eclipse或Studio在代码上划一条线是什么意思?
- 【转】Delphi XE图解为Android应用制作签名