springbeanfactory.java
来自「本文论述了一个前台笔记本销售系统的开发过程」· Java 代码 · 共 44 行
JAVA
44 行
package com.set.appframe.business;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.set.appframe.exception.SystemException;
public class SpringBeanFactory {
protected static AbstractApplicationContext ctx = null;
private static SpringBeanFactory instance = null;
private SpringBeanFactory() {
init();
}
private void init() {
if (null == ctx) {
String paths[] = { "classpath*:applicationContext-*.xml" };
ctx = new ClassPathXmlApplicationContext(paths);
}
}
public static SpringBeanFactory getInstance() {
if (null == instance) {
instance = new SpringBeanFactory();
}
return instance;
}
public Object getBean(String name) throws SystemException {
Object bean = null;
try {
bean = ctx.getBean(name);
} catch (Exception ex) {
throw new SystemException("error.springconfig");
}
return bean;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?