List of usage examples for org.springframework.context.support GenericApplicationContext start
@Override public void start()
From source file:org.anarres.dblx.core.Main.java
public static void main(String[] args) throws Exception { Stopwatch stopwatch = Stopwatch.createStarted(); Arguments arguments = new Arguments(args); GenericApplicationContext context = new GenericApplicationContext(); AnnotatedBeanDefinitionReader reader = new AnnotatedBeanDefinitionReader(context); reader.register(AppConfiguration.class); for (AppConfiguration.Provider configurationProvider : ServiceLoader .load(AppConfiguration.Provider.class)) { for (Class<?> configurationClass : configurationProvider.getConfigurationClasses()) { LOG.debug("Registering additional ServerConfiguration class " + configurationClass.getName()); reader.register(configurationClass); }//ww w .ja v a 2 s. c om } SpringUtils.addConfigurations(context, arguments); context.refresh(); context.registerShutdownHook(); context.start(); LOG.info("Ready; startup took " + stopwatch); }
From source file:com.opengamma.language.connector.LanguageSpringContext.java
/** * Creates a Spring context from the base configuration file in OG-Language and any other Spring XML configuration * files found in the configuration directory. The directory must be specified using the system property named * {@link #LANGUAGE_EXT_PATH}.//from w w w. j av a 2s . co m * @return A Spring context built from all the XML config files. */ public static GenericApplicationContext createSpringContext() { s_logger.info("Starting OpenGamma language integration service"); GenericApplicationContext context = new GenericApplicationContext(); final XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(context); xmlReader.loadBeanDefinitions(new ClassPathResource(CLIENT_XML)); String[] xmlFiles = findSpringXmlConfig(); xmlReader.loadBeanDefinitions(xmlFiles); s_logger.info("Creating context beans"); context.refresh(); s_logger.info("Starting application context"); context.start(); s_logger.info("Application context started"); return context; }
From source file:com.opengamma.engine.calcnode.CalculationNodeProcess.java
private static boolean startContext(final String configuration) { try {/*from w ww . j a v a 2 s . c om*/ final GenericApplicationContext context = new GenericApplicationContext(); final XmlBeanDefinitionReader beanReader = new XmlBeanDefinitionReader(context); beanReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_NONE); s_logger.debug("Loading configuration"); beanReader.loadBeanDefinitions(new InputSource(new StringReader(configuration))); s_logger.debug("Instantiating beans"); context.refresh(); s_logger.debug("Starting node"); context.start(); return true; } catch (RuntimeException e) { s_logger.warn("Spring initialisation error", e); return false; } }
From source file:com.github.yihtserns.logback.spring.config.LogbackNamespaceHandlerTest.java
private static GenericApplicationContext newApplicationContextFor(String xml) { GenericApplicationContext applicationContext = new GenericApplicationContext(); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(applicationContext); xmlReader.setValidationMode(XmlBeanDefinitionReader.VALIDATION_XSD); xmlReader.loadBeanDefinitions(new InputSource(new StringReader(xml))); applicationContext.refresh();//from w w w. j av a 2 s. c o m applicationContext.start(); return applicationContext; }
From source file:org.alfresco.cacheserver.dropwizard.Application.java
public void start() { if (springContextFileLocation != null) { // parent spring context with the normal DropWizard configuration defined GenericApplicationContext parent = new GenericApplicationContext(); parent.refresh();//from www .j ava 2 s . c o m parent.getBeanFactory().registerSingleton("configuration", this); parent.registerShutdownHook(); parent.start(); try { PropertyPlaceholderConfigurer configurer = loadSpringConfigurer(yamlConfigFileLocation); // child spring context from xml context = new ClassPathXmlApplicationContext(parent); if (configurer != null) { context.addBeanFactoryPostProcessor(configurer); } context.setConfigLocations(new String[] { springContextFileLocation }); context.registerShutdownHook(); context.refresh(); } catch (IOException e) { throw new IllegalStateException("Could not create Spring context", e); } } else { throw new IllegalArgumentException("Spring context file location not set"); } }
From source file:org.jacpfx.vertx.spring.SpringVerticleFactory.java
private Verticle createSpringVerticle(final Class<?> currentVerticleClass, ClassLoader classLoader) { final SpringVerticle annotation = currentVerticleClass.getAnnotation(SpringVerticle.class); final Class<?> springConfigClass = annotation.springConfig(); // Create the parent context final GenericApplicationContext genericApplicationContext = new GenericApplicationContext(); genericApplicationContext.setClassLoader(classLoader); if (parentContext != null) { genericApplicationContext.setParent(parentContext); }/* ww w . j a va2 s. c om*/ genericApplicationContext.refresh(); genericApplicationContext.start(); // 1. Create a new context for each verticle and use the specified spring configuration class if possible AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext(); annotationConfigApplicationContext.setParent(genericApplicationContext); annotationConfigApplicationContext.register(SpringContextConfiguration.class, springConfigClass); // 2. Register a bean definition for this verticle annotationConfigApplicationContext.registerBeanDefinition(currentVerticleClass.getSimpleName(), new VerticleBeanDefinition(currentVerticleClass)); // 3. Add a bean factory post processor to avoid configuration issues annotationConfigApplicationContext .addBeanFactoryPostProcessor(new SpringSingleVerticleConfiguration(currentVerticleClass)); annotationConfigApplicationContext.refresh(); annotationConfigApplicationContext.start(); annotationConfigApplicationContext.registerShutdownHook(); // 5. Return the verticle by fetching the bean from the context return (Verticle) annotationConfigApplicationContext.getBeanFactory() .getBean(currentVerticleClass.getSimpleName()); }