servicefactory.java

来自「sping下勇Xdoclet开发hibernate的程序实例,版本hiberna」· Java 代码 · 共 51 行

JAVA
51
字号
/*
 * Created on 2004-8-13
 * 
 * TODO To change the template for this generated file go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
package org.ggyy.util;

import org.ggyy.dao.ICatDao;
import org.ggyy.dao.IOwnerDao;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
/**
 * bean实例的类工厂,从spring容器管理的bean中得到bean的实例,这是给Junit测试用的.
 * 服务器运行时,bean的实例由spring容器产生
 * @author jiangyubao
 *
 */
public final class ServiceFactory {
    private static ICatDao catDao = null;

    private static IOwnerDao ownerDao = null;

    private static ApplicationContext ctx = null;
    static {
        ctx = new FileSystemXmlApplicationContext(
                "WebRoot/WEB-INF/applicationContext.xml");
    }

    private ServiceFactory() {

    }

    public static ApplicationContext getApplicationContext() {
        return ctx;
    }

    public static ICatDao getICatDao() {
        if (catDao == null) {
            catDao = (ICatDao) ctx.getBean("catDao");
        }
        return catDao;
    }
    public static IOwnerDao getIOwnerDao() {
        if (ownerDao == null) {
            ownerDao = (IOwnerDao) ctx.getBean("ownerDao");
        }
        return ownerDao;
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?