<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    探索與發現

    研究java技術

      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
      83 隨筆 :: 0 文章 :: 109 評論 :: 0 Trackbacks

    把spring集成到web框架很簡單,只要在web.xml里面加上
    <context-param>
    ??? <param-name>contextConfigLocation</param-name>
    ??? <param-value>/WEB-INF/applicationContext*.xml</param-value>
    </context-param>
    或者
    <listener>
    ??? <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    如果為下面這種方式的話,那么就是加載默認的文件
    /WEB-INF/applicationContext.xml
    這個在
    org.springframework.web.context.support.XmlWebApplicationContext類里面定義的,,部分代碼:
    /** Default config location for the root context */
    ?public static final String DEFAULT_CONFIG_LOCATION = "/WEB-INF/applicationContext.xml";

    ?/** Default prefix for building a config location for a namespace */
    ?public static final String DEFAULT_CONFIG_LOCATION_PREFIX = "/WEB-INF/";

    ?/** Default suffix for building a config location for a namespace */
    ?public static final String DEFAULT_CONFIG_LOCATION_SUFFIX = ".xml";


    Once the context files are loaded, Spring creates a WebApplicationContext object based on the bean definitions and puts it into the ServletContext.
    這樣我們就可以直接用ServletContext獲取自己想要的參數的,,

    All Java web frameworks are built on top of the Servlet API, so you can use the following code to get the ApplicationContext that Spring created.

    WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext);

    通過WebApplicationContext我們就可以通過bean的名字獲取它的實例了
    The WebApplicationContextUtils class is for convenience, so you don't have to remember the name of the ServletContext attribute. Its getWebApplicationContext() method will return null if an object doesn't exist under the WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE key. Rather than risk getting NullPointerExceptions in your application, it's better to use the getRequiredWebApplicationContext() method. This method throws an Exception when the ApplicationContext is missing.

    Once you have a reference to the WebApplicationContext, you can retrieve beans by their name or type. Most developers retrieve beans by name, then cast them to one of their implemented interfaces.

    Fortunately, most of the frameworks in this section have simpler ways of looking up beans. Not only do they make it easy to get beans from the BeanFactory, but they also allow you to use dependency injection on their controllers. Each framework section has more detail on its specific integration strategies.

    posted on 2006-08-02 23:41 蜘蛛 閱讀(628) 評論(0)  編輯  收藏 所屬分類: spring

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 亚洲国产精品免费观看 | 国产黄色片免费看| 亚洲妓女综合网99| 亚洲色大成网站WWW久久九九| 国产成人免费爽爽爽视频| 国产精品99久久免费观看| 女bbbbxxxx另类亚洲| 亚洲精品二三区伊人久久| 久久亚洲国产午夜精品理论片| 国产传媒在线观看视频免费观看| www视频在线观看免费| 国产一级片免费看| 有色视频在线观看免费高清在线直播 | 亚洲人成未满十八禁网站| 亚洲人成网站在线播放影院在线 | 无码亚洲成a人在线观看| 亚洲精品国产精品国自产网站| 久久精品国产亚洲AV无码娇色| 亚洲午夜久久久影院| 亚洲国产成人五月综合网| 日本免费电影一区| 岛国大片免费在线观看| 免费精品国产自产拍在| 久久九九兔免费精品6| 外国成人网在线观看免费视频| 国产免费无码AV片在线观看不卡| 久久成人18免费网站| 国产成人精品免费大全| 一出一进一爽一粗一大视频免费的| 国产亚洲漂亮白嫩美女在线| 色噜噜噜噜亚洲第一| 精品亚洲视频在线| 免费在线观看亚洲| 美女羞羞喷液视频免费| 亚洲人成网站免费播放| 亚洲av午夜国产精品无码中文字| 亚洲欧美精品午睡沙发| 亚洲精品天堂成人片AV在线播放 | 国产三级免费观看| 免费大片黄手机在线观看| 四虎影视永久免费视频观看|