下面列出了org.springframework.context.support.FileSystemXmlApplicationContext#close ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static void main(String[] args)
{
if (args.length != 2)
{
System.err.println("Usage:");
System.err.println("java " + DbToXML.class.getName() + " <context.xml> <output.xml>");
System.exit(1);
}
String contextPath = args[0];
File outputFile = new File(args[1]);
// Create the Spring context
FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(contextPath);
DbToXML dbToXML = new DbToXML(context, outputFile);
dbToXML.execute();
// Shutdown the Spring context
context.close();
}
public JarContainerServer(String filename) {
FileSystemXmlApplicationContext serverContext = new FileSystemXmlApplicationContext(filename);
HapporServerElement element = serverContext.getBean(HapporServerElement.class);
server = element.getServer();
containerConfig = element.getConfigs().get("container");
log4jConfig = element.getConfigs().get("log4j");
serverContext.close();
}
/**
* Unloads a context (Red5 application) and removes it from the context map, then removes it's beans from the parent (that is, Red5)
*
* @param name
* Context name
*/
public void unloadContext(String name) {
log.debug("Un-load context - name: {}", name);
ApplicationContext context = contextMap.remove(name);
log.debug("Context from map: {}", context);
String[] bnames = BeanFactoryUtils.beanNamesIncludingAncestors(context);
for (String bname : bnames) {
log.debug("Bean: {}", bname);
}
ConfigurableBeanFactory factory = ((ConfigurableApplicationContext) applicationContext).getBeanFactory();
if (factory.containsSingleton(name)) {
log.debug("Context found in parent, destroying: {}", name);
FileSystemXmlApplicationContext ctx = (FileSystemXmlApplicationContext) factory.getSingleton(name);
if (ctx.isRunning()) {
log.debug("Context was running, attempting to stop");
ctx.stop();
}
if (ctx.isActive()) {
log.debug("Context is active, attempting to close");
ctx.close();
} else {
try {
factory.destroyBean(name, ctx);
} catch (Exception e) {
log.warn("Context destroy failed for: {}", name, e);
} finally {
if (factory.containsSingleton(name)) {
log.debug("Singleton still exists, trying another destroy method");
((DefaultListableBeanFactory) factory).destroySingleton(name);
}
}
}
} else {
log.debug("Context does not contain singleton: {}", name);
}
context = null;
}