单例模式的问题
请问,像下面代码在spring项目中,context变量会频繁初始化吗,applicationcontext.xml文件会频繁加载吗,因而过多占用内存吗?private static final String xml = "applicationcontext.xml";
private static ApplicationContext context;
private static Object getBeanService(String serviceName) {
Object bean = null;
try {
if (context == null) {
context = new ClassPathXmlApplicationContext(xml);
//context = SpringApplicationContextUtil.getApplicationContext();
}
bean = context.getBean(serviceName);
} catch (Exception e) {
e.printStackTrace();
}
return bean;
}