factoryloaderlistener.java

来自「基于j2ee的电子留言系统」· Java 代码 · 共 48 行

JAVA
48
字号
package org.yeeku.web;

import javax.servlet.*;
import org.yeeku.factory.*;
import org.hibernate.SessionFactory;

/**
 * @author  yeeku.H.lee kongyeeku@163.com
 * @version  1.0
 * <br>Copyright (C), 2005-2008, yeeku.H.Lee
 * <br>This program is protected by copyright laws.
 * <br>Program Name:
 * <br>Date: 
 */
public class FactoryLoaderListener implements ServletContextListener
{ 
	DaoFactory df = null;
	SessionFactory sf = null;
    public void contextInitialized(ServletContextEvent sce)
    {
		try
		{
			sf = SessionFactoryBuilder.instance().getSessionFactory();
			System.out.println("Hibernate的SessionFactory已经被初始化... " + sf);	
		}
		catch (Exception e)
		{
			System.out.println("初始化SessionFactory工厂时出现异常" + e);
		}
		try
		{
			String path = sce.getServletContext().getRealPath("/WEB-INF/");
			df = DaoFactory.instance(path);
			System.out.println("DAO工厂已经被初始化... " + df);

		}
		catch (Exception e)
		{
			System.out.println("初始化DAO工厂时出现异常" + e);
		}
    } 
    
    public void contextDestroyed(ServletContextEvent sce)
    {
		sf = null;
		df = null;
    } 
} 

⌨️ 快捷键说明

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