List of usage examples for org.springframework.context.support AbstractXmlApplicationContext close
@Override public void close()
From source file:de.hoegertn.demo.cxfsimple.SpringStarter.java
public final void doStart() throws Exception { try {// w w w .j a v a2 s. c o m this.doBeforeSpringStart(); } catch (Exception e) { throw new RuntimeException("Before spring failed", e); } Lock writeLock = this.rwLock.writeLock(); AbstractXmlApplicationContext ctx = null; try { writeLock.lock(); if (this.context.get() != null) { throw new RuntimeException("Already started"); } ctx = this.createSpringContext(); final PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); configurer.setProperties(System.getProperties()); ctx.addBeanFactoryPostProcessor(configurer); ctx.setConfigLocation(this.getSpringResource()); ctx.refresh(); } catch (Exception e) { if (ctx != null) { try { ctx.close(); } catch (Exception e1) { this.logger.warn("Failed to close context", e1); } ctx = null; } throw new RuntimeException("Spring context failed", e); } finally { if (ctx != null) { this.context.set(ctx); } writeLock.unlock(); } try { this.doAfterSpringStart(); } catch (Exception e) { throw new RuntimeException("After spring failed", e); } }
From source file:de.taimos.daemon.spring.SpringDaemonAdapter.java
@Override public final void doStart() throws Exception { super.doStart(); try {/*from ww w. j av a2 s . c o m*/ this.doBeforeSpringStart(); } catch (Exception e) { throw new RuntimeException("Before spring failed", e); } Lock writeLock = this.rwLock.writeLock(); AbstractXmlApplicationContext ctx = null; try { writeLock.lock(); if (this.context.get() != null) { throw new RuntimeException("Already started"); } ctx = this.createSpringContext(); String[] profiles = System.getProperty(Configuration.PROFILES, Configuration.PROFILES_PRODUCTION) .split(","); ctx.getEnvironment().setActiveProfiles(profiles); final PropertySourcesPlaceholderConfigurer configurer = new PropertySourcesPlaceholderConfigurer(); configurer.setProperties(DaemonStarter.getDaemonProperties()); ctx.addBeanFactoryPostProcessor(configurer); ctx.setConfigLocation(this.getSpringResource()); ctx.refresh(); } catch (Exception e) { if (ctx != null) { try { ctx.close(); } catch (Exception e1) { this.logger.warn("Failed to close context", e1); } ctx = null; } throw new RuntimeException("Spring context failed", e); } finally { if (ctx != null) { this.context.set(ctx); } writeLock.unlock(); } try { this.doAfterSpringStart(); } catch (Exception e) { throw new RuntimeException("After spring failed", e); } }