⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 appcontext.java

📁 SSH的平台搭建
💻 JAVA
字号:
package com.lovo.zengxy.util;

import java.io.FileNotFoundException;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;

/**
 * 用于获取spring配置文件的bean的工具类
 * @author fw
 *
 */
public class AppContext {
	
	private AppContext(){
		
	}
	
	private static AppContext app = null;
	private static StringBuilder sb = null;
	
	public static synchronized AppContext getAppContext()
	{
		if(app==null)
		{
			app = new AppContext();
			sb = new StringBuilder();
		}
		return app;
	}
	
	public Object getBean(String beanName,String springConfigFileName) throws FileNotFoundException
	{
		Resource resource = new FileSystemResource(this.getPath(springConfigFileName));
        BeanFactory factory = new XmlBeanFactory(resource);
	    return factory.getBean(beanName);
	}
	
	public static final String PATH="../webapps/webgame/web-inf/config/";
	
	private String getPath(String springConfigFileName)
	{
		sb.append(PATH);
		sb.append(springConfigFileName);
		return sb.toString();
	}

}

⌨️ 快捷键说明

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