常用的 SpringHelper 类方法
唐弘和
2023-12-01
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class SpringHelper {
static ApplicationContext ctx = null;
static {
try {
String[] s = new String[] { "applicationContext-dao.xml",
"applicationContext-biz.xml" };
ctx = new ClassPathXmlApplicationContext(s);
} catch (Exception e) {
e.printStackTrace();
}
}
public static Object getBean(String beanId) {
try {
return ctx.getBean(beanId);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}