<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在线观看播放免费视频日本| 永久在线观看免费视频| 青青草原亚洲视频| 丁香花在线观看免费观看| 久久青青草原亚洲av无码| 亚洲成人免费在线观看| 亚洲w码欧洲s码免费| va亚洲va日韩不卡在线观看| 国产99久久亚洲综合精品| 亚洲精品A在线观看| 99久久99这里只有免费的精品| 成人黄页网站免费观看大全| 亚洲AV日韩精品久久久久久| 日韩免费电影网站| 亚洲精品中文字幕无乱码麻豆| 四虎一区二区成人免费影院网址| 91免费播放人人爽人人快乐| 亚洲αv在线精品糸列| 污污网站免费观看| 亚洲噜噜噜噜噜影院在线播放| 一级做a爱过程免费视| 久久久久久久尹人综合网亚洲| 亚洲综合激情五月色一区| 久久精品免费一区二区| 亚洲色精品三区二区一区| 国产一级高清视频免费看| eeuss影院ss奇兵免费com| 亚洲精品私拍国产福利在线| 成人免费在线观看网站| 三上悠亚电影全集免费| 亚洲成人黄色在线| 亚洲成a人片在线观看久| 国产成人亚洲综合无| 亚洲精品V欧洲精品V日韩精品| 精品无码免费专区毛片| 成人免费视频一区二区| 亚洲黄色在线视频| 亚洲精品成人a在线观看| 国产成人精品免费视频动漫| 爱情岛论坛免费视频|