List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext FileSystemXmlApplicationContext
public FileSystemXmlApplicationContext(String... configLocations) throws BeansException
From source file:org.craftercms.cstudio.publishing.StopServiceMain.java
public static void main(String[] args) throws Exception { FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext( "classpath:spring/shutdown-context.xml"); ReadablePropertyPlaceholderConfigurer properties = (ReadablePropertyPlaceholderConfigurer) context .getBean("cstudioShutdownProperties"); if (properties != null) { String url = getProperty(properties, PROP_URL); String path = getProperty(properties, PROP_SERVICE_PATH); String port = getProperty(properties, PROP_PORT); String password = URLEncoder.encode(getProperty(properties, PROP_PASSWORD), "UTF-8"); String target = url + ":" + port + path; if (LOGGER.isDebugEnabled()) { LOGGER.debug("Sending a stop request to " + target); }/*from www . j a v a 2s . c o m*/ target = target + "?" + StopServiceServlet.PARAM_PASSWORD + "=" + password; URL serviceUrl = new URL(target); HttpURLConnection connection = (HttpURLConnection) serviceUrl.openConnection(); connection.setRequestMethod("GET"); connection.setReadTimeout(10000); connection.connect(); try { connection.getContent(); } catch (ConnectException e) { // ignore this error (server will terminate as soon as the request is sent out) } } else { if (LOGGER.isErrorEnabled()) { LOGGER.error(PROPERTIES_NAME + " is not present in shutdown-context.xml"); } } context.close(); }
From source file:com.px100systems.data.utility.RestoreUtility.java
public static void main(String[] args) { if (args.length < 3) { System.err.println("Usage: java -cp ... com.px100systems.data.utility.RestoreUtility " + "<springXmlConfigFile> <persisterBeanName> <backupDirectory> [compare]"); return;/*from w w w.jav a 2s .c om*/ } FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext("file:" + args[0]); try { PersistenceProvider persister = ctx.getBean(args[1], PersistenceProvider.class); File directory = new File(args[2]); if (!directory.isDirectory()) { System.err.println(directory.getName() + " is not a directory"); return; } List<File> files = new ArrayList<File>(); //noinspection ConstantConditions for (File file : directory.listFiles()) if (BackupFile.isBackup(file)) files.add(file); if (files.isEmpty()) { System.err.println(directory.getName() + " directory has no backup files"); return; } if (args.length == 4 && args[3].equalsIgnoreCase("compare")) { final Map<String, Map<Long, RawRecord>> units = new HashMap<String, Map<Long, RawRecord>>(); for (String storage : persister.storage()) { System.out.println("Storage " + storage); persister.loadByStorage(storage, new PersistenceProvider.LoadCallback() { @Override public void process(RawRecord record) { Map<Long, RawRecord> unitList = units.get(record.getUnitName()); if (unitList == null) { unitList = new HashMap<Long, RawRecord>(); units.put(record.getUnitName(), unitList); } unitList.put(record.getId(), record); } }); for (final Map.Entry<String, Map<Long, RawRecord>> unit : units.entrySet()) { BackupFile file = null; for (int i = 0, n = files.size(); i < n; i++) if (BackupFile.isBackup(files.get(i), unit.getKey())) { file = new BackupFile(files.get(i)); files.remove(i); break; } if (file == null) throw new RuntimeException("Could not find backup file for unit " + unit.getKey()); final Long[] count = new Long[] { 0L }; file.read(new PersistenceProvider.LoadCallback() { @Override public void process(RawRecord record) { RawRecord r = unit.getValue().get(record.getId()); if (r == null) throw new RuntimeException("Could not find persisted record " + record.getId() + " for unit " + unit.getKey()); if (!r.equals(record)) throw new RuntimeException( "Record " + record.getId() + " mismatch for unit " + unit.getKey()); count[0] = count[0] + 1; } }); if (count[0] != unit.getValue().size()) throw new RuntimeException("Extra persisted records for unit " + unit.getKey()); System.out.println(" Unit " + unit.getKey() + ": OK"); } units.clear(); } if (!files.isEmpty()) { System.err.println("Extra backups: "); for (File file : files) System.err.println(" " + file.getName()); } } else { persister.init(); for (File file : files) { InMemoryDatabase.readBackupFile(file, persister); System.out.println("Loaded " + file.getName()); } } } catch (Exception e) { throw new RuntimeException(e); } finally { ctx.close(); } }
From source file:com.paxxis.cornerstone.service.spring.CornerstoneService.java
/** * The main/*www. j av a2 s. c o m*/ * * @param args the command line arguments. There should be only * 1 command line argument -- the spring factory xml file. */ public static void main(String[] args) { // all we do is load the container FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(args[0]); ctx.registerShutdownHook(); }
From source file:project.latex.balloon.BalloonController.java
/** * @param args the command line arguments *//*w w w.ja v a 2s. co m*/ public static void main(String[] args) { PropertyConfigurator.configure("logger.properties"); logger.info("Project Latex Balloon Controller, version 0.1"); ApplicationContext context = new FileSystemXmlApplicationContext("beans.xml"); BalloonController balloonController = (BalloonController) context.getBean("balloonController"); logger.info("Balloon created"); balloonController.run(); }
From source file:org.echocat.nodoodle.server.Main.java
public static void main(String[] args) { final File log4jConfig = new File(System.getProperty("log4j.configuration", "../config/log4j.xml")); if (log4jConfig.isFile()) { try {//from w w w. j a v a2s .c o m final FileReader reader = new FileReader(log4jConfig); try { final DOMConfigurator domConfigurator = new DOMConfigurator(); domConfigurator.doConfigure(reader, getLoggerRepository()); } finally { IOUtils.closeQuietly(reader); } } catch (Exception e) { throw new RuntimeException("Could not configure log4j with " + log4jConfig + ".", e); } } final String applicationName = getApplicationName(); //System.setSecurityManager(new ServerSecurityManager()); LOG.info("Starting " + applicationName + "..."); final File config = new File( System.getProperty(Main.class.getPackage().getName() + ".config", "../config/nodoodleServer.xml")); final AbstractApplicationContext applicationContext = new FileSystemXmlApplicationContext(config.getPath()); LOG.info("Starting " + applicationName + "... DONE!"); Runtime.getRuntime().addShutdownHook(new Thread("destroyer") { @Override public void run() { LOG.info("Stopping " + applicationName + "..."); applicationContext.stop(); LOG.info("Stopping " + applicationName + "... DONE!"); } }); }
From source file:edu.vt.middleware.cas.ldap.LoadDriver.java
public static void main(final String[] args) { if (args.length < 4) { System.out.println("USAGE: LoadDriver sample_count thread_count " + "path/to/credentials.csv path/to/spring-context.xml"); return;// w ww . j a v a 2 s. co m } final int samples = Integer.parseInt(args[0]); final int threads = Integer.parseInt(args[1]); final File credentials = new File(args[2]); if (!credentials.exists()) { throw new IllegalArgumentException(credentials + " does not exist."); } ApplicationContext context; try { context = new ClassPathXmlApplicationContext(args[3]); } catch (BeanDefinitionStoreException e) { if (e.getCause() instanceof FileNotFoundException) { // Try treating path as filesystem path context = new FileSystemXmlApplicationContext(args[3]); } else { throw e; } } final LoadDriver driver = new LoadDriver(samples, threads, credentials, context); System.err.println("Load test configuration:"); System.err.println("\tthreads: " + threads); System.err.println("\tsamples: " + samples); System.err.println("\tcredentials: " + credentials); driver.start(); while (driver.getState().hasWorkRemaining()) { try { Thread.sleep(1000); } catch (InterruptedException e) { } } driver.stop(); }
From source file:com.turbospaces.api.EmbeddedJSpaceRunner.java
/** * launcher method// w ww . j a va 2s. c o m * * @param args * [1 argument = application context path] * @throws Exception * re-throw execution errors if any */ public static void main(final String... args) throws Exception { JVMUtil.gcOnExit(); String appContextPath = args[0]; if (System.getProperty(Global.IPv4) == null && System.getProperty(Global.IPv6) == null) System.setProperty(Global.IPv4, Boolean.TRUE.toString()); System.setProperty(Global.CUSTOM_LOG_FACTORY, JGroupsCustomLoggerFactory.class.getName()); LOGGER.info("Welcome to turbospaces:version = {}, build date = {}", SpaceUtility.projectVersion(), SpaceUtility.projecBuildTimestamp()); LOGGER.info("{}: launching configuration {}", EmbeddedJSpaceRunner.class.getSimpleName(), appContextPath); AbstractXmlApplicationContext c = appContextPath.startsWith("file") ? new FileSystemXmlApplicationContext(appContextPath) : new ClassPathXmlApplicationContext(appContextPath); c.getBeansOfType(JSpace.class); c.registerShutdownHook(); Collection<SpaceConfiguration> configurations = c.getBeansOfType(SpaceConfiguration.class).values(); for (SpaceConfiguration spaceConfiguration : configurations) spaceConfiguration.joinNetwork(); LOGGER.info("all jspaces joined network, notifying waiting threads..."); synchronized (joinNetworkMonitor) { joinNetworkMonitor.notifyAll(); } while (!Thread.currentThread().isInterrupted()) synchronized (c) { try { c.wait(TimeUnit.SECONDS.toMillis(1)); } catch (InterruptedException e) { LOGGER.info("got interruption signal, terminating jspaces... stack_trace = {}", Throwables.getStackTraceAsString(e)); Thread.currentThread().interrupt(); Util.printThreads(); } } c.destroy(); }
From source file:org.openvpms.archetype.test.tools.TestTaskGenerator.java
/** * Main line.//from ww w . j ava 2s . c o m * * @param args the command line arguments */ public static void main(String[] args) { String contextPath = "applicationContext.xml"; if (!new File(contextPath).exists()) { new ClassPathXmlApplicationContext(contextPath); } else { new FileSystemXmlApplicationContext(contextPath); } Party[] workLists = new Party[10]; for (int i = 0; i < workLists.length; ++i) { Entity taskType = ScheduleTestHelper.createTaskType("XTaskType-" + (i + 1), true); Party workList = ScheduleTestHelper.createWorkList(100, taskType); workList.setName("XWorkList-" + (i + 1)); save(workList); workLists[i] = workList; } ScheduleTestHelper.createWorkListView(workLists); Date startTime = DateRules.getDate(DateRules.getTomorrow()); User clinician = createClinician(); for (int i = 0; i < 100; ++i) { Party customer = TestHelper.createCustomer("", "ZCustomer " + (i + 1), true); Party patient = TestHelper.createPatient(customer); patient.setName("ZPatient " + (i + 1)); for (Party workList : workLists) { Act task = ScheduleTestHelper.createTask(startTime, null, workList, customer, patient, clinician, clinician); save(task); } } }
From source file:ru.goodsReview.api.Main.java
public static void main(String[] args) throws IOException, JSONException { final FileSystemXmlApplicationContext storageContext = new FileSystemXmlApplicationContext( "src/main/resources/database.xml"); DataSource ds = (DataSource) storageContext.getBean("dataSource"); ThesisDbController thesisDbController = new ThesisDbController(new SimpleJdbcTemplate(ds)); List<Thesis> thesisList = thesisDbController.getAllTheses(); int count = 0; for (Thesis thesis : thesisList) { count++;// w ww . j a v a 2 s .c o m System.out.println(thesis.getContent()); } System.out.println(count); }
From source file:au.edu.uws.eresearch.cr8it.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments// w w w.ja v a 2s.c o m */ public static void main(final String... args) { String contextFilePath = "spring-integration-context.xml"; String configFilePath = "config/config-file.groovy"; String environment = System.getProperty("environment"); if (LOGGER.isInfoEnabled()) { LOGGER.info("\n=========================================================" + "\n " + "\n Welcome to C8it Integration! " + "\n " + "\n For more information please visit: " + "\n http://www.springsource.org/spring-integration " + "\n " + "\n========================================================="); } ConfigObject config = Config.getConfig(environment, configFilePath); Map configMap = config.flatten(); System.setProperty("environment", environment); System.setProperty("cr8it.client.config.file", (String) configMap.get("file.runtimePath")); //final AbstractApplicationContext context = //new ClassPathXmlApplicationContext("classpath:META-INF/spring/integration/*-context.xml"); String absContextPath = "config/integration/" + contextFilePath; File contextFile = new File(absContextPath); final AbstractApplicationContext context; if (!contextFile.exists()) { absContextPath = "classpath:" + absContextPath; context = new ClassPathXmlApplicationContext(absContextPath); } else { absContextPath = "file:" + absContextPath; context = new FileSystemXmlApplicationContext(absContextPath); } context.registerShutdownHook(); SpringIntegrationUtils.displayDirectories(context); final Scanner scanner = new Scanner(System.in); if (LOGGER.isInfoEnabled()) { LOGGER.info("\n=========================================================" + "\n " + "\n Please press 'q + Enter' to quit the application. " + "\n " + "\n========================================================="); } while (!scanner.hasNext("q")) { //Do nothing unless user presses 'q' to quit. } if (LOGGER.isInfoEnabled()) { LOGGER.info("Exiting application...bye."); } System.exit(0); }