List of usage examples for org.springframework.context.support GenericApplicationContext GenericApplicationContext
public GenericApplicationContext(@Nullable ApplicationContext parent)
From source file:net.itransformers.idiscover.v2.core.Main.java
public static void main(String[] args) throws MalformedURLException { logger.debug("iDiscover v2. gearing up"); Map<String, String> params = CmdLineParser.parseCmdLine(args); // String connectionDetailsFileName = params.get("-f"); // if (connectionDetailsFileName == null) { // printUsage("fileName"); return; // }/*from www . j ava2s. c om*/ String depthCmdArg = params.get("-d"); // if (depthCmdArg == null) { // printUsage("depth"); return; // } String projectPath = params.get("-p"); if (projectPath == null) { File cwd = new File("."); System.out.println("Project path is not specified. Will use current dir: " + cwd.getAbsolutePath()); projectPath = cwd.getAbsolutePath(); } File workingDir = new File(projectPath); if (!workingDir.exists()) { System.out.println("Invalid project path!"); return; } System.out.println("Loading beans!!"); File conDetails = new File(projectPath, "iDiscover/conf/txt/connection-details.txt"); File generic = new File(projectPath, "iDiscover/conf/xml/generic.xml"); String genericContextPath = generic.toURI().toURL().toString(); File snmpDiscovery = new File(projectPath, "iDiscover/conf/xml/snmpNetworkDiscovery.xml"); String snmpDiscoveryContextPath = snmpDiscovery.toURI().toURL().toString(); File connectionsDetails = new File(projectPath, "iDiscover/conf/xml/connectionsDetails.xml"); String connectionsDetailsContextPath = connectionsDetails.toURI().toURL().toString(); DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory(); BeanDefinition beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(String.class) .addConstructorArgValue(projectPath).getBeanDefinition(); String labelDirName = autolabel(projectPath); BeanDefinition beanDefinition2 = BeanDefinitionBuilder.rootBeanDefinition(String.class) .addConstructorArgValue(labelDirName).getBeanDefinition(); beanFactory.registerBeanDefinition("projectPath", beanDefinition); beanFactory.registerBeanDefinition("labelDirName", beanDefinition2); GenericApplicationContext cmdArgCxt = new GenericApplicationContext(beanFactory); // Must call refresh to initialize context cmdArgCxt.refresh(); String[] paths = new String[] { genericContextPath, snmpDiscoveryContextPath, connectionsDetailsContextPath }; // ,project.getAbsolutePath()+project.getAbsolutePath()+File.separator+"iDiscover/conf/xml/snmpNetworkDiscovery.xml", project.getAbsolutePath()+File.separator+"iDiscover/src/main/resources/connectionsDetails.xml" FileSystemXmlApplicationContext applicationContext = new FileSystemXmlApplicationContext(paths, cmdArgCxt); // ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(workingDir+File.separator+"iDiscover/conf/xml/generic.xml",workingDir+File.separator+"/iDiscover/conf/xml/snmpNetworkDiscovery.xml","connectionsDetails.xml"); // NetworkDiscoverer discoverer = fileApplicationContext.getBean("bgpPeeringMapDiscovery", NetworkDiscoverer.class); //NetworkDiscoverer discoverer = fileApplicationContext.getBean("floodLightNodeDiscoverer", NetworkDiscoverer.class); NetworkDiscoverer discoverer = applicationContext.getBean("snmpDiscovery", NetworkDiscoverer.class); LinkedHashMap<String, ConnectionDetails> connectionList = (LinkedHashMap) applicationContext .getBean("connectionList", conDetails); int depth = (Integer) applicationContext.getBean("discoveryDepth", depthCmdArg == null ? "-1" : depthCmdArg); NetworkDiscoveryResult result = discoverer .discoverNetwork(new ArrayList<ConnectionDetails>(connectionList.values()), depth); if (result != null) { for (String s : result.getNodes().keySet()) { System.out.println("\nNode: " + s); } } // }
From source file:de.visualdependencies.context.ContextUtil.java
/** * Creates and return a new Spring context object. * //w w w. j a v a 2 s . co m * This creates a complete new context including data abstraction layer and plugin management. All plugins defined * in the application's package will recognized. * * @return applicationContext */ public static GenericApplicationContext initialize() { // Creating the context for database configuration. final GenericXmlApplicationContext contextDatabase = new GenericXmlApplicationContext( "classpath:context-database.xml"); final GenericApplicationContext context = new GenericApplicationContext(contextDatabase); context.refresh(); return context; }
From source file:net.cpollet.jixture.spring.TestConfiguration.java
@Test public void springConfigurationIsWorking() { GenericApplicationContext applicationContext = new GenericApplicationContext( // new ClassPathXmlApplicationContext("classpath:/spring/jpa2-unit-test-context.xml")); for (String beanName : applicationContext.getBeanDefinitionNames()) { if (!applicationContext.getBeanDefinition(beanName).isAbstract()) { logger.info("Requesting bean {}", beanName); applicationContext.getBean(beanName); }//from ww w . jav a 2s .co m } }
From source file:org.jwebsocket.spring.JWebSocketBeanFactory.java
public static GenericApplicationContext getInstance() { if (null == mGlobalContext) { mGlobalContext = new GenericApplicationContext(new DefaultListableBeanFactory()); }// w w w . jav a 2s .co m return mGlobalContext; }
From source file:org.jwebsocket.spring.JWebSocketBeanFactory.java
public static GenericApplicationContext getInstance(String aNamespace) { if (!mContextMap.containsKey(aNamespace)) { mContextMap.put(aNamespace, new GenericApplicationContext(new DefaultListableBeanFactory())); //Setting the default (core) application context as parent mContextMap.get(aNamespace).setParent(mGlobalContext); }// w w w . j a v a 2s . co m return mContextMap.get(aNamespace); }
From source file:ch.nydi.spring.context.support.TestGenericXmlContextLoader.java
/** * {@inheritDoc}/*w ww .jav a 2s. c om*/ */ @Override public final ConfigurableApplicationContext loadContext(final String... locations) throws Exception { final DefaultListableBeanFactory beanFactory = new PrimaryResolverListableBeanFactory(); beanFactory.setParameterNameDiscoverer(new LocalVariableTableParameterNameDiscoverer()); beanFactory.setAutowireCandidateResolver(new QualifierAnnotationAutowireCandidateResolver()); final GenericApplicationContext context = new GenericApplicationContext(beanFactory); createBeanDefinitionReader(context).loadBeanDefinitions(locations); AnnotationConfigUtils.registerAnnotationConfigProcessors(context); context.refresh(); context.registerShutdownHook(); return context; }
From source file:org.twinkql.template.AbstractTwinkqlTemplateFactory.java
/** * Gets the twinkql template.//from w ww. ja v a 2 s .c om * * @return the twinkql template * @throws Exception the exception */ public TwinkqlTemplate getTwinkqlTemplate() { DefaultListableBeanFactory parentBeanFactory = new DefaultListableBeanFactory(); parentBeanFactory.registerSingleton("twinkqlContext", this.getTwinkqlContext()); GenericApplicationContext parentContext = new GenericApplicationContext(parentBeanFactory); parentContext.refresh(); AnnotationConfigApplicationContext annotationConfigApplicationContext = this .decorateContext(new AnnotationConfigApplicationContext()); annotationConfigApplicationContext.setParent(parentContext); annotationConfigApplicationContext.scan(PACKAGE_SCAN); annotationConfigApplicationContext.refresh(); TwinkqlTemplate template = annotationConfigApplicationContext.getBean(TwinkqlTemplate.class); return template; }
From source file:org.alfresco.util.bean.DynamicContextLoader.java
/** * Iterates through the list of ContextLoaderEvaluators and loads the additional * contexts if appropriate./* w w w. j a v a2 s.c om*/ */ public void init() { GenericApplicationContext childContext = new GenericApplicationContext(applicationContext); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(childContext); boolean isContextChanged = false; for (ContextLoaderEvaluator contextLoaderEvaluator : contextLoaderEvaluators) { if (contextLoaderEvaluator.loadContext()) { if (logger.isInfoEnabled()) { logger.info( "Loading dynamic context: " + contextLoaderEvaluator.getContextResource().toString()); } xmlReader.loadBeanDefinitions(contextLoaderEvaluator.getContextResource()); isContextChanged = true; } else { if (logger.isInfoEnabled()) { logger.info( "Skipping dynamic context: " + contextLoaderEvaluator.getContextResource().toString()); } } } if (isContextChanged) { childContext.refresh(); } }
From source file:org.rosenvold.spring.convention.ConventionContextLoader.java
public final ConfigurableApplicationContext loadContext(String... locations) throws Exception { ConventionBeanFactory conventionBeanFactory = new ConventionBeanFactory(createNameToClassResolver(), createCandidateEvaluator()); GenericApplicationContext context = new GenericApplicationContext(conventionBeanFactory); prepareContext(context);//w w w . j a v a 2 s. c o m customizeBeanFactory(context.getDefaultListableBeanFactory()); createBeanDefinitionReader(context).loadBeanDefinitions(locations); AnnotationConfigUtils.registerAnnotationConfigProcessors(context); customizeContext(context); context.refresh(); context.registerShutdownHook(); return context; }
From source file:com.retroduction.carma.application.CarmaDriverSetup.java
public void init() { GenericApplicationContext newAppContext = new GenericApplicationContext(this.parentContext); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(newAppContext); for (String res : this.beanDefinitionResources) { xmlReader.loadBeanDefinitions(res); }/*from w w w .j a v a 2 s . co m*/ PropertyPlaceholderConfigurer customerPropsProcessor = new PropertyPlaceholderConfigurer(); customerPropsProcessor.setProperties(this.configurationParameters); newAppContext.addBeanFactoryPostProcessor(customerPropsProcessor); newAppContext.refresh(); newAppContext.registerShutdownHook(); this.appContext = newAppContext; }