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

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

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

    Junky's IT Notebook

    統(tǒng)計(jì)

    留言簿(8)

    積分與排名

    WebSphere Studio

    閱讀排行榜

    評(píng)論排行榜

    ServiceLocator的實(shí)現(xiàn)

    ServiceLocator的實(shí)現(xiàn)

    /*

    * 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 閱讀(1412) 評(píng)論(0)  編輯  收藏 所屬分類: spring

    主站蜘蛛池模板: 亚洲人成人77777网站不卡| 亚洲s码欧洲m码吹潮| 美女视频黄免费亚洲| 精品国产日韩亚洲一区91| 亚洲国产精品狼友中文久久久| 在线观看黄片免费入口不卡| 亚洲日本国产精华液| 四虎影在线永久免费观看| 国产日韩AV免费无码一区二区| 亚洲一区在线免费观看| 国产美女无遮挡免费视频| 丝袜足液精子免费视频| 亚洲中文字幕久久无码| 亚洲人成网站在线观看播放| 久久久久国产精品免费免费搜索 | 三上悠亚亚洲一区高清| 1000部免费啪啪十八未年禁止观看| 亚洲精品天堂无码中文字幕| 国产国拍亚洲精品mv在线观看| 成人人免费夜夜视频观看| 国产又黄又爽又大的免费视频 | 麻豆国产精品免费视频| 在线观看亚洲视频| 亚洲成a人片毛片在线| 亚洲精品国精品久久99热| 4虎永免费最新永久免费地址| 人成午夜免费大片在线观看| 97久久国产亚洲精品超碰热| 亚洲精品无码午夜福利中文字幕| 成年轻人网站色免费看 | 浮力影院亚洲国产第一页| 噼里啪啦电影在线观看免费高清| a级毛片免费观看视频| 午夜亚洲国产精品福利| 亚洲精品二三区伊人久久| 亚洲AV中文无码乱人伦下载| 九月婷婷亚洲综合在线| 毛片免费全部播放一级| 精品无码免费专区毛片| 久久青草免费91观看| 丁香花在线观看免费观看图片|