隨筆-295  評論-26  文章-1  trackbacks-0

          ?Spring中ApplicationContext加載機制。
          ????? ??? 加載器目前有兩種選擇:ContextLoaderListener和ContextLoaderServlet。
          ???????? 這兩者在功能上完全等同,只是一個是基于Servlet2.3版本中新引入的Listener接口實現(xiàn),而另一個基于Servlet接口實現(xiàn)。開發(fā)中可根據(jù)目標Web容器的實際情況進行選擇。

          配置非常簡單,在web.xml中增加:
          <listener>
          ? <listener-class>
          ?????? org.springframework.web.context.ContextLoaderListener
          ? </listener-class>
          </listener>
          或:
          <servlet>
          ??? <servlet-name>context</servlet-name>
          ??? <servlet-class>
          ?????? org.springframework.web.context.ContextLoaderServlet
          ??? </servlet-class>
          ??? <load-on-startup>1</load-on-startup>
          </servlet>?
          ?
          ????????? 通過以上配置,Web容器會自動加載/WEB-INF/applicationContext.xml初始化
          ApplicationContext實例,如果需要指定配置文件位置,可通過context-param加以指定:
          <context-param>
          ??? <param-name>contextConfigLocation</param-name>
          ??? <param-value>/WEB-INF/myApplicationContext.xml</param-value>
          </context-param>

          ??????? 配置完成之后,即可通過
          ?WebApplicationContextUtils.getWebApplicationContext方法在Web應用中獲取ApplicationContext引用。

          如:ApplicationContext ctx=WebApplicationContextUtils.getWebApplicationContext();
          ??? LoginAction action=(LoginAction)ctx.getBean("action");



          大盤預測 國富論
          posted on 2007-08-27 16:03 華夢行 閱讀(175) 評論(0)  編輯  收藏 所屬分類: Spring
          主站蜘蛛池模板: 尼木县| 西华县| 文登市| 开鲁县| 北票市| 元氏县| 金昌市| 温州市| 贵阳市| 冀州市| 罗田县| 中西区| 壶关县| 含山县| 宜章县| 垫江县| 镇远县| 黄龙县| 关岭| 赞皇县| 阿城市| 普宁市| 武陟县| 永善县| 禄丰县| 石门县| 柘城县| 安陆市| 田东县| 遵义市| 依兰县| 绥芬河市| 克拉玛依市| 上思县| 塔河县| 南岸区| 额尔古纳市| 雷州市| 中宁县| 乳山市| 六枝特区|