springutil.java

来自「这是一个上传下载的原代码」· Java 代码 · 共 57 行

JAVA
57 行
字号
package com.project.util;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import com.model.logic.UserLogic;

/*
 *  创建人:杨森
 *  创建时间:2007-9-7
 *  描述:实现spring配置文件bean
 *  最后修改时间:
 *  最后修改人:
 */
public class SpringUtil {
	public String path1 = null;
	public String path2 = null;
	
	public UserLogic logic;
	
	public String getPath1() {
		return path1;
	}
	public void setPath1(String path1) {
		this.path1 = path1;
	}
	public String getPath2() {
		return path2;
	}
	public void setPath2(String path2) {
		this.path2 = path2;
	}
	public UserLogic getLogic() {
		return logic;
	}
	public void setLogic(UserLogic logic) {
		this.logic = logic;
	}
	
	//获取spring配置文件
	public SpringUtil getInstance(){
		String path = this.getClass().getResource("/").getFile()+"../../WEB-INF/config/applicationcontext.xml";
		ApplicationContext ctx = new FileSystemXmlApplicationContext(path.replaceAll("%20", " "));

		return (SpringUtil)ctx.getBean("SpringUtil");
	}
	//获取逻辑层
	public Object getLogicBean(String beanName){
		String[] paths = new String[]{path1,path2};
		ApplicationContext xmlFactory = new FileSystemXmlApplicationContext(paths);
		
      	return xmlFactory.getBean(beanName);
	}

	
}

⌨️ 快捷键说明

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