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

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

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

    Junky's IT Notebook

    統計

    留言簿(8)

    積分與排名

    WebSphere Studio

    閱讀排行榜

    評論排行榜

    ServiceLocator的實現

    ServiceLocator的實現

    /*

    * Created on 2004-8-25 by simba.

    *

    */

    package com.simba.blog.util;

    ?

    ?

    import javax.servlet.ServletContext;

    ?

    import org.apache.commons.logging.Log;

    import org.apache.commons.logging.LogFactory;

    import org.springframework.context.ApplicationContext;

    import org.springframework.web.context.support.WebApplicationContextUtils;

    ?

    import com.opensymphony.webwork.ServletActionContext;

    import com.simba.blog.service.BlogService;

    ?

    /**

    * @author simba

    *

    * email: simbasun@msn.com

    */

    public class ServiceLocator

    {

    //the catalog service bean name

    private static final String BLOG_SERVICE_BEAN_NAME = "blogService";

    ?

    //the user service bean name

    private static final String USER_SERVICE_BEAN_NAME = "userService";

    ?

    //the logger for this class

    private Log logger = LogFactory.getLog(this.getClass());

    ?

    //the Spring application context

    private ApplicationContext appContext;

    ?

    //the cached catalog service

    private BlogService blogService;

    ?

    //the cached user service

    //private UserService userService;

    ?

    /**

    * Constructor.

    * <p>

    * The following steps being done:

    * <ul>

    * <li>retrieve Spring application context from servlet context.

    * <li>look up <code>CatalogService</code> from Spring application

    * context.

    * <li>look up <code>UserService</code> from Spring applicatino context.

    * </ul>

    */

    public ServiceLocator()

    {

    /*InputStream is = getClass().getResourceAsStream("springapp-servlet.xml");

    XmlBeanFactory bf = new XmlBeanFactory(is);

    blogService = (BlogService) bf.getBean("blogService");*/

    ?

    ServletContext context = ServletActionContext.getServletContext();

    this.appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(context);

    this.blogService = (BlogService)this.lookupService(BLOG_SERVICE_BEAN_NAME);

    ?

    /*

    * this.userService = (UserService)this.lookupService(USER_SERVICE_BEAN_NAME);

    */

    ?

    this.logger.info("Service locator bean is initialized");

    }

    ?

    ?

    /**

    * Lookup service based on service bean name.

    *

    * @param serviceBeanName the service bean name

    * @return the service bean

    */

    public Object lookupService(String serviceBeanName)

    {

    return appContext.getBean(serviceBeanName);

    }

    ?

    /**

    * @return Returns the blogService.

    */

    public BlogService getBlogService()

    {

    return blogService;

    }

    }

    ?

    ?

    ?

    [in web.xml]

    ?

    <context-param>

    <param-name>contextConfigLocation</param-name>

    <param-value>/WEB-INF/daoContext.xml /WEB-INF/applicationContext.xml</param-value>

    </context-param>

    <listener>

    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

    </listener>

    <!-- OR USE THE CONTEXTLOADERSERVLET INSTEAD OF THE LISTENER

    <servlet>

    <servlet-name>context</servlet-name>

    <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>

    <load-on-startup>1</load-on-startup>

    </servlet>

    -->

    posted on 2006-10-17 14:06 junky 閱讀(1411) 評論(0)  編輯  收藏 所屬分類: spring

    主站蜘蛛池模板: 韩国免费三片在线视频| WWW国产成人免费观看视频| xxxx日本免费| 亚洲综合激情九月婷婷| 最近中文字幕电影大全免费版| 久久久婷婷五月亚洲97号色| 67pao强力打造高清免费| 亚洲国产情侣一区二区三区| 久久国内免费视频| 亚洲精品无码少妇30P| 日韩亚洲国产二区| 国产性生大片免费观看性| 亚洲AV无码成人网站久久精品大 | mm1313亚洲精品无码又大又粗 | 老汉精品免费AV在线播放| 久久久亚洲欧洲日产国码二区| 美女内射毛片在线看免费人动物 | 亚洲人成伊人成综合网久久久| 日韩免费观看一区| 日本亚洲精品色婷婷在线影院| 韩国欧洲一级毛片免费| 2022免费国产精品福利在线| 亚洲高清国产AV拍精品青青草原| 蜜桃成人无码区免费视频网站| 亚洲色欲色欲www| 免费在线观看a级毛片| 人妻无码一区二区三区免费| 亚洲av无码国产综合专区| 亚洲成?v人片天堂网无码| 国产成人精品一区二区三区免费| 亚洲国产视频一区| 亚洲国产精品毛片av不卡在线| 国产免费阿v精品视频网址| 亚洲色大18成人网站WWW在线播放| 亚洲真人日本在线| 成人在线免费看片| 国产免费福利体检区久久| 亚洲人色大成年网站在线观看| www亚洲一级视频com| 久久九九兔免费精品6| a高清免费毛片久久|