public class SpringUtil {
private static ClassPathXmlApplicationContext ctx;
private static final String configPath="applicationContext.xml";
public static synchronized <T> T getBean(Class<T> beanCls) {
if (ctx == null) {
ctx = new ClassPathXmlApplicationContext(configPath);
ctx.registerShutdownHook();
}
return ctx.getBean(beanCls);
}
public static synchronized <T> T getBean(String beanName) {
if (ctx == null) {
ctx = new ClassPathXmlApplicationContext(configPath);
ctx.registerShutdownHook();
}
return (T)ctx.getBean(beanName);
}
public static synchronized void shutdown()
{
if(ctx!=null)
{
ctx.close();
ctx=null;
}
}
}
Zeroc Ice 学习笔记--集成Ice与Spring(参考Zeroc Ice 权威指南)
最新推荐文章于 2025-05-01 14:35:26 发布