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

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

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

    探索與發(fā)現(xiàn)

    研究java技術(shù)

      BlogJava :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      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>
    如果為下面這種方式的話,那么就是加載默認(rèn)的文件
    /WEB-INF/applicationContext.xml
    這個(gè)在
    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獲取自己想要的參數(shù)的,,

    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的名字獲取它的實(shí)例了
    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 蜘蛛 閱讀(631) 評論(0)  編輯  收藏 所屬分類: spring

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


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲视频免费一区| 亚洲日韩AV一区二区三区四区 | 久久精品国产亚洲麻豆| 理论秋霞在线看免费| 免费大学生国产在线观看p| 亚洲av永久无码精品秋霞电影秋 | 久久久久国产免费| 亚洲免费在线视频| 67pao强力打造国产免费| 久久夜色精品国产噜噜噜亚洲AV | 免费人成视频在线播放| 亚洲乱码日产精品a级毛片久久| 日韩在线视精品在亚洲| 亚洲精品tv久久久久久久久久| gogo免费在线观看| 亚洲AV日韩AV永久无码绿巨人| 99爱在线观看免费完整版| 亚洲三级在线免费观看| 午夜寂寞在线一级观看免费| 日本黄页网址在线看免费不卡| 国产专区一va亚洲v天堂| 国产成人精品无码免费看| 亚洲综合激情五月丁香六月| 成人au免费视频影院| 香港经典a毛片免费观看看| 亚洲午夜福利在线观看| 在线免费观看亚洲| 亚洲av纯肉无码精品动漫| 亚洲伊人久久综合影院| 99热这里有免费国产精品| 中文字幕亚洲男人的天堂网络| 国产免费69成人精品视频| 日韩免费在线视频| 亚洲精品伦理熟女国产一区二区| ZZIJZZIJ亚洲日本少妇JIZJIZ| 久久精品一本到99热免费| 亚洲av日韩专区在线观看| 亚洲AV无码专区国产乱码电影 | 中文字幕亚洲无线码a| 最近免费中文在线视频| 精品国产日韩亚洲一区91|