List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext FileSystemXmlApplicationContext
public FileSystemXmlApplicationContext(String[] configLocations, boolean refresh) throws BeansException
From source file:myjpa.guest.model.Test.java
public static void main(String[] args) { ApplicationContext ctx = new FileSystemXmlApplicationContext("web/WEB-INF/applicationContext.xml", "web/WEB-INF/dispatcher-servlet.xml"); Guests guests = ctx.getBean("guests", Guests.class); // int guestId = guests.insert(new Guest("Hello World", "Wee")); // System.out.println("Guest Id:" + guestId); for (Guest g : guests.findAll(2, 3)) { System.out.println(g);//from ww w . j a va2s . co m } }
From source file:org.sonews.Application.java
/** * The main entrypoint./*from ww w . j a v a 2 s.co m*/ * * @param args * @throws Exception */ public static void main(String[] args) throws Exception { System.out.println(VERSION); Thread.currentThread().setName("Mainthread"); // Command line arguments boolean async = false; boolean feed = false; // Enable feeding? boolean purger = false; // Enable message purging? int port = -1; for (int n = 0; n < args.length; n++) { switch (args[n]) { case "-async": { async = true; break; } case "-c": case "-config": { Config.inst().set(Config.LEVEL_CLI, Config.CONFIGFILE, args[++n]); System.out.println("Using config file " + args[n]); break; } case "-C": case "-context": { // FIXME: Additional context files n++; break; } case "-dumpjdbcdriver": { System.out.println("Available JDBC drivers:"); Enumeration<Driver> drvs = DriverManager.getDrivers(); while (drvs.hasMoreElements()) { System.out.println(drvs.nextElement()); } return; } case "-feed": { feed = true; break; } case "-h": case "-help": { printArguments(); return; } case "-p": { port = Integer.parseInt(args[++n]); break; } case "-plugin-storage": { System.out.println("Warning: -plugin-storage is not implemented!"); break; } case "-purger": { purger = true; break; } case "-v": case "-version": // Simply return as the version info is already printed above return; } } ApplicationContext context = new AnnotationConfigApplicationContext(Application.class); context = new FileSystemXmlApplicationContext(new String[] { "sonews.xml" }, context); // Enable storage backend StorageProvider sprov = context.getBean("storageProvider", StorageProvider.class); StorageManager.enableProvider(sprov); ChannelLineBuffers.allocateDirect(); // Add shutdown hook Runtime.getRuntime().addShutdownHook(new ShutdownHook()); // Start the listening daemon if (port <= 0) { port = Config.inst().get(Config.PORT, 119); } NNTPDaemon daemon = context.getBean(NNTPDaemon.class); daemon.setPort(port); daemon.start(); // Start Connections purger thread... Connections.getInstance().start(); // Start feeds if (feed) { FeedManager.startFeeding(); } if (purger) { Purger purgerDaemon = new Purger(); purgerDaemon.start(); } // Wait for main thread to exit (setDaemon(false)) daemon.join(); }
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 w w w. ja va 2s.c o m*/ 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:io.s4.MainApp.java
public static void main(String args[]) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("corehome").hasArg().withDescription("core home").create("c")); options.addOption(// ww w .j a va 2s. co m OptionBuilder.withArgName("appshome").hasArg().withDescription("applications home").create("a")); options.addOption(OptionBuilder.withArgName("s4clock").hasArg().withDescription("s4 clock").create("d")); options.addOption(OptionBuilder.withArgName("seedtime").hasArg() .withDescription("event clock initialization time").create("s")); options.addOption( OptionBuilder.withArgName("extshome").hasArg().withDescription("extensions home").create("e")); options.addOption( OptionBuilder.withArgName("instanceid").hasArg().withDescription("instance id").create("i")); options.addOption( OptionBuilder.withArgName("configtype").hasArg().withDescription("configuration type").create("t")); CommandLineParser parser = new GnuParser(); CommandLine commandLine = null; String clockType = "wall"; try { commandLine = parser.parse(options, args); } catch (ParseException pe) { System.err.println(pe.getLocalizedMessage()); System.exit(1); } int instanceId = -1; if (commandLine.hasOption("i")) { String instanceIdStr = commandLine.getOptionValue("i"); try { instanceId = Integer.parseInt(instanceIdStr); } catch (NumberFormatException nfe) { System.err.println("Bad instance id: %s" + instanceIdStr); System.exit(1); } } if (commandLine.hasOption("c")) { coreHome = commandLine.getOptionValue("c"); } if (commandLine.hasOption("a")) { appsHome = commandLine.getOptionValue("a"); } if (commandLine.hasOption("d")) { clockType = commandLine.getOptionValue("d"); } if (commandLine.hasOption("e")) { extsHome = commandLine.getOptionValue("e"); } String configType = "typical"; if (commandLine.hasOption("t")) { configType = commandLine.getOptionValue("t"); } long seedTime = 0; if (commandLine.hasOption("s")) { seedTime = Long.parseLong(commandLine.getOptionValue("s")); } File coreHomeFile = new File(coreHome); if (!coreHomeFile.isDirectory()) { System.err.println("Bad core home: " + coreHome); System.exit(1); } File appsHomeFile = new File(appsHome); if (!appsHomeFile.isDirectory()) { System.err.println("Bad applications home: " + appsHome); System.exit(1); } if (instanceId > -1) { System.setProperty("instanceId", "" + instanceId); } else { System.setProperty("instanceId", "" + S4Util.getPID()); } List loArgs = commandLine.getArgList(); if (loArgs.size() < 1) { // System.err.println("No bean configuration file specified"); // System.exit(1); } // String s4ConfigXml = (String) loArgs.get(0); // System.out.println("s4ConfigXml is " + s4ConfigXml); ClassPathResource propResource = new ClassPathResource("s4-core.properties"); Properties prop = new Properties(); if (propResource.exists()) { prop.load(propResource.getInputStream()); } else { System.err.println("Unable to find s4-core.properties. It must be available in classpath"); System.exit(1); } ApplicationContext coreContext = null; String configBase = coreHome + File.separatorChar + "conf" + File.separatorChar + configType; String configPath = ""; List<String> coreConfigUrls = new ArrayList<String>(); File configFile = null; // load clock configuration configPath = configBase + File.separatorChar + clockType + "-clock.xml"; coreConfigUrls.add(configPath); // load core config xml configPath = configBase + File.separatorChar + "s4-core-conf.xml"; configFile = new File(configPath); if (!configFile.exists()) { System.err.printf("S4 core config file %s does not exist\n", configPath); System.exit(1); } coreConfigUrls.add(configPath); String[] coreConfigFiles = new String[coreConfigUrls.size()]; coreConfigUrls.toArray(coreConfigFiles); String[] coreConfigFileUrls = new String[coreConfigFiles.length]; for (int i = 0; i < coreConfigFiles.length; i++) { coreConfigFileUrls[i] = "file:" + coreConfigFiles[i]; } coreContext = new FileSystemXmlApplicationContext(coreConfigFileUrls, coreContext); ApplicationContext context = coreContext; Clock s4Clock = (Clock) context.getBean("clock"); if (s4Clock instanceof EventClock && seedTime > 0) { EventClock s4EventClock = (EventClock) s4Clock; s4EventClock.updateTime(seedTime); System.out.println("Intializing event clock time with seed time " + s4EventClock.getCurrentTime()); } PEContainer peContainer = (PEContainer) context.getBean("peContainer"); Watcher w = (Watcher) context.getBean("watcher"); w.setConfigFilename(configPath); // load extension modules String[] configFileNames = getModuleConfigFiles(extsHome, prop); if (configFileNames.length > 0) { String[] configFileUrls = new String[configFileNames.length]; for (int i = 0; i < configFileNames.length; i++) { configFileUrls[i] = "file:" + configFileNames[i]; } context = new FileSystemXmlApplicationContext(configFileUrls, context); } // load application modules configFileNames = getModuleConfigFiles(appsHome, prop); if (configFileNames.length > 0) { String[] configFileUrls = new String[configFileNames.length]; for (int i = 0; i < configFileNames.length; i++) { configFileUrls[i] = "file:" + configFileNames[i]; } context = new FileSystemXmlApplicationContext(configFileUrls, context); // attach any beans that implement ProcessingElement to the PE // Container String[] processingElementBeanNames = context.getBeanNamesForType(ProcessingElement.class); for (String processingElementBeanName : processingElementBeanNames) { Object bean = context.getBean(processingElementBeanName); try { Method getS4ClockMethod = bean.getClass().getMethod("getS4Clock"); if (getS4ClockMethod.getReturnType().equals(Clock.class)) { if (getS4ClockMethod.invoke(bean) == null) { Method setS4ClockMethod = bean.getClass().getMethod("setS4Clock", Clock.class); setS4ClockMethod.invoke(bean, coreContext.getBean("clock")); } } } catch (NoSuchMethodException mnfe) { // acceptable } System.out.println("Adding processing element with bean name " + processingElementBeanName + ", id " + ((ProcessingElement) bean).getId()); peContainer.addProcessor((ProcessingElement) bean, processingElementBeanName); } } }
From source file:org.apache.s4.MainApp.java
public static void main(String args[]) throws Exception { Options options = new Options(); options.addOption(OptionBuilder.withArgName("corehome").hasArg().withDescription("core home").create("c")); options.addOption(//from w w w . jav a2 s .c o m OptionBuilder.withArgName("appshome").hasArg().withDescription("applications home").create("a")); options.addOption(OptionBuilder.withArgName("s4clock").hasArg().withDescription("s4 clock").create("d")); options.addOption(OptionBuilder.withArgName("seedtime").hasArg() .withDescription("event clock initialization time").create("s")); options.addOption( OptionBuilder.withArgName("extshome").hasArg().withDescription("extensions home").create("e")); options.addOption( OptionBuilder.withArgName("instanceid").hasArg().withDescription("instance id").create("i")); options.addOption( OptionBuilder.withArgName("configtype").hasArg().withDescription("configuration type").create("t")); CommandLineParser parser = new GnuParser(); CommandLine commandLine = null; String clockType = "wall"; try { commandLine = parser.parse(options, args); } catch (ParseException pe) { System.err.println(pe.getLocalizedMessage()); System.exit(1); } int instanceId = -1; if (commandLine.hasOption("i")) { String instanceIdStr = commandLine.getOptionValue("i"); try { instanceId = Integer.parseInt(instanceIdStr); } catch (NumberFormatException nfe) { System.err.println("Bad instance id: %s" + instanceIdStr); System.exit(1); } } if (commandLine.hasOption("c")) { coreHome = commandLine.getOptionValue("c"); } if (commandLine.hasOption("a")) { appsHome = commandLine.getOptionValue("a"); } if (commandLine.hasOption("d")) { clockType = commandLine.getOptionValue("d"); } if (commandLine.hasOption("e")) { extsHome = commandLine.getOptionValue("e"); } String configType = "typical"; if (commandLine.hasOption("t")) { configType = commandLine.getOptionValue("t"); } long seedTime = 0; if (commandLine.hasOption("s")) { seedTime = Long.parseLong(commandLine.getOptionValue("s")); } File coreHomeFile = new File(coreHome); if (!coreHomeFile.isDirectory()) { System.err.println("Bad core home: " + coreHome); System.exit(1); } File appsHomeFile = new File(appsHome); if (!appsHomeFile.isDirectory()) { System.err.println("Bad applications home: " + appsHome); System.exit(1); } if (instanceId > -1) { System.setProperty("instanceId", "" + instanceId); } else { System.setProperty("instanceId", "" + S4Util.getPID()); } List loArgs = commandLine.getArgList(); if (loArgs.size() < 1) { // System.err.println("No bean configuration file specified"); // System.exit(1); } // String s4ConfigXml = (String) loArgs.get(0); // System.out.println("s4ConfigXml is " + s4ConfigXml); ClassPathResource propResource = new ClassPathResource("s4-core.properties"); Properties prop = new Properties(); if (propResource.exists()) { prop.load(propResource.getInputStream()); } else { System.err.println("Unable to find s4-core.properties. It must be available in classpath"); System.exit(1); } ApplicationContext coreContext = null; String configBase = coreHome + File.separatorChar + "conf" + File.separatorChar + configType; String configPath = ""; List<String> coreConfigUrls = new ArrayList<String>(); File configFile = null; // load clock configuration configPath = configBase + File.separatorChar + clockType + "-clock.xml"; coreConfigUrls.add(configPath); // load core config xml configPath = configBase + File.separatorChar + "s4-core-conf.xml"; configFile = new File(configPath); if (!configFile.exists()) { System.err.printf("S4 core config file %s does not exist\n", configPath); System.exit(1); } coreConfigUrls.add(configPath); String[] coreConfigFiles = new String[coreConfigUrls.size()]; coreConfigUrls.toArray(coreConfigFiles); String[] coreConfigFileUrls = new String[coreConfigFiles.length]; for (int i = 0; i < coreConfigFiles.length; i++) { coreConfigFileUrls[i] = "file:" + coreConfigFiles[i]; } coreContext = new FileSystemXmlApplicationContext(coreConfigFileUrls, coreContext); ApplicationContext context = coreContext; Clock clock = (Clock) context.getBean("clock"); if (clock instanceof EventClock && seedTime > 0) { EventClock s4EventClock = (EventClock) clock; s4EventClock.updateTime(seedTime); System.out.println("Intializing event clock time with seed time " + s4EventClock.getCurrentTime()); } PEContainer peContainer = (PEContainer) context.getBean("peContainer"); Watcher w = (Watcher) context.getBean("watcher"); w.setConfigFilename(configPath); // load extension modules String[] configFileNames = getModuleConfigFiles(extsHome, prop); if (configFileNames.length > 0) { String[] configFileUrls = new String[configFileNames.length]; for (int i = 0; i < configFileNames.length; i++) { configFileUrls[i] = "file:" + configFileNames[i]; } context = new FileSystemXmlApplicationContext(configFileUrls, context); } // load application modules configFileNames = getModuleConfigFiles(appsHome, prop); if (configFileNames.length > 0) { String[] configFileUrls = new String[configFileNames.length]; for (int i = 0; i < configFileNames.length; i++) { configFileUrls[i] = "file:" + configFileNames[i]; } context = new FileSystemXmlApplicationContext(configFileUrls, context); // attach any beans that implement ProcessingElement to the PE // Container String[] processingElementBeanNames = context.getBeanNamesForType(AbstractPE.class); for (String processingElementBeanName : processingElementBeanNames) { AbstractPE bean = (AbstractPE) context.getBean(processingElementBeanName); bean.setClock(clock); try { bean.setSafeKeeper((SafeKeeper) context.getBean("safeKeeper")); } catch (NoSuchBeanDefinitionException ignored) { // no safe keeper = no checkpointing / recovery } // if the application did not specify an id, use the Spring bean name if (bean.getId() == null) { bean.setId(processingElementBeanName); } System.out.println("Adding processing element with bean name " + processingElementBeanName + ", id " + ((AbstractPE) bean).getId()); peContainer.addProcessor((AbstractPE) bean); } } }
From source file:com.dp.bigdata.taurus.restlet.RestletTest.java
@Test public void testMain() { ApplicationContext context = new FileSystemXmlApplicationContext("classpath:applicationContext-core.xml", "classpath:applicationContext-restlet.xml"); Engine engine = (Engine) context.getBean("engine"); Component restlet = (Component) context.getBean("component"); try {/*from ww w .j a va 2 s . c om*/ restlet.start(); engine.start(); System.out.println(String.format("[%s] [INFO] Press any key to stop server ... ", 1)); System.in.read(); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.red5.server.plugin.policy.PolicyServerPlugin.java
public void doStart() throws Exception { log.debug("Start"); // create app context try {//from www . j a v a2s .c o m configContext = new FileSystemXmlApplicationContext( new String[] { "${red5.root}/plugins/policycontext.xml" }, true); } catch (Exception e) { configContext = new FileSystemXmlApplicationContext(new String[] { "classpath:/policycontext.xml" }, true); } }
From source file:org.red5.server.Launcher.java
/** * Launch Red5 under it's own classloader *//*from ww w . j av a 2s. co m*/ public void launch() { System.out.printf("Root: %s\nDeploy type: %s\nLogback selector: %s\n", System.getProperty("red5.root"), System.getProperty("red5.deployment.type"), System.getProperty("logback.ContextSelector")); try { // install the slf4j bridge (mostly for JUL logging) SLF4JBridgeHandler.install(); // we create the logger here so that it is instanced inside the expected classloader // check for the logback disable flag boolean useLogback = Boolean.valueOf(System.getProperty("useLogback", "true")); Red5LoggerFactory.setUseLogback(useLogback); // get the first logger Logger log = Red5LoggerFactory.getLogger(Launcher.class); // version info banner log.info("{} (http://code.google.com/p/red5/)", Red5.getVersion()); // pimp red5 System.out.printf("%s (http://code.google.com/p/red5/)\n", Red5.getVersion()); // create red5 app context FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext( new String[] { "classpath:/red5.xml" }, false); // set the current threads classloader as the loader for the factory/appctx ctx.setClassLoader(Thread.currentThread().getContextClassLoader()); // refresh must be called before accessing the bean factory ctx.refresh(); /* if (log.isTraceEnabled()) { String[] names = ctx.getBeanDefinitionNames(); for (String name : names) { log.trace("Bean name: {}", name); } } */ } catch (Throwable t) { System.out.printf("Exception %s\n", t); System.exit(9999); } }
From source file:org.hbird.business.core.Starter.java
/** * Method to read the XML assembly file and run the main * //from w ww.jav a 2 s .c o m * @throws Exception */ @SuppressWarnings("resource") protected void boot() throws Exception { LOG.info("Starting Hummingbird based system."); Main main = new Main(); main.enableHangupSupport(); /* Read the configuration file as the first argument. If not set, then we try the default name. */ String assemblyFile = System.getProperty("hbird.assembly") == null ? "classpath:main.xml" : System.getProperty("hbird.assembly"); LOG.info("Reading assembly file '{}'", assemblyFile); FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(new String[] { assemblyFile }, false); context.setDisplayName(CONTEXT_NAME + "-" + (++counter)); LOG.info("Created Spring AppicationContext '{}'", context.getDisplayName()); context.refresh(); main.run(); }
From source file:com.liferay.portal.test.TestUtil.java
public static ApplicationContext initSpringForPortlet(String portletName) throws Exception { setPortletClassLoader();//from w ww .ja va 2 s. c o m List<String> configLocations = getPortletConfigLocations(portletName); BeanLocatorImpl impl = (BeanLocatorImpl) PortalBeanLocatorUtil.getBeanLocator(); ApplicationContext parent = impl.getApplicationContext(); String[] locations = configLocations.toArray(new String[0]); ApplicationContext context = new FileSystemXmlApplicationContext(locations, parent); return context; }