List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext FileSystemXmlApplicationContext
public FileSystemXmlApplicationContext(String... configLocations) throws BeansException
From source file:org.openspaces.admin.application.ApplicationFileDeployment.java
private static ApplicationConfig readConfigFromXmlFile(final String applicationFilePath) throws BeansException { ApplicationConfig config;// w w w. j av a 2 s. c o m // Convert to URL to workaround the "everything is a relative paths problem" // see spring documentation 5.7.3 FileSystemResource caveats. String fileUri = new File(applicationFilePath).toURI().toString(); final FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(fileUri); try { //CR: Catch runtime exceptions. convert to AdminException(s) context.refresh(); config = context.getBean(ApplicationConfig.class); } finally { if (context.isActive()) { context.close(); } } return config; }
From source file:org.skife.jdbi.spring.TestSpringIntegration.java
public void setUp() throws Exception { System.setProperty(LogFactoryImpl.LOG_PROPERTY, NoOpLog.class.getName()); Tools.start();/*from w ww . ja va2s.c om*/ Tools.dropAndCreateSomething(); if (ctx == null) { ctx = new FileSystemXmlApplicationContext(CTX_BASE); } }
From source file:org.springframework.data.hadoop.admin.util.HadoopWorkflowDescriptorUtilsTest.java
@Test public void testReplacePropertyPlaceHolder() { String fileName = "src/test/resources/org/springframework/data/hadoop/admin/util/context.xml"; String properFilename = "src/test/resources/org/springframework/data/hadoop/admin/util/hadoop.properties"; File f = new File(fileName); File propertiesFile = new File(properFilename); logger.debug("path:" + f.getParentFile().getAbsolutePath()); if (f != null) { try {/*from w w w.j a v a2 s . c o m*/ util.replacePropertyPlaceHolder(f, propertiesFile); } catch (SpringHadoopAdminWorkflowException e) { fail("exception was thrown when replacing proeprty place holder." + e.getMessage()); } } FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(fileName); SimpleBean bean = ctx.getBean("simpleBean", SimpleBean.class); Assert.assertEquals( "file://src/test/resources/org/springframework/data/hadoop/admin/util/hadoop-examples-1.0.0.jar", bean.getPath()); }
From source file:org.springframework.integration.samples.async.gateway.AsyncGatewayTest.java
@Test public void testAsyncGateway() throws Exception { ConfigurableApplicationContext ac = new FileSystemXmlApplicationContext( "src/main/resources/META-INF/spring/integration/*.xml"); MathServiceGateway mathService = ac.getBean("mathService", MathServiceGateway.class); Map<Integer, Future<Integer>> results = new HashMap<Integer, Future<Integer>>(); Random random = new Random(); for (int i = 0; i < 100; i++) { int number = random.nextInt(200); Future<Integer> result = mathService.multiplyByTwo(number); results.put(number, result);/* w ww. j a v a 2 s. c o m*/ } for (final Map.Entry<Integer, Future<Integer>> resultEntry : results.entrySet()) { executor.execute(() -> { int[] result = processFuture(resultEntry); if (result[1] == -1) { logger.info("Multiplying " + result[0] + " should be easy. You should be able to multiply any number < 100 by 2 in your head"); } else if (result[1] == -2) { logger.info("Multiplication of " + result[0] + " by 2 is can not be accomplished in " + timeout + " seconds"); } else { logger.info("Result of multiplication of " + result[0] + " by 2 is " + result[1]); } }); } executor.shutdown(); executor.awaitTermination(60, TimeUnit.SECONDS); logger.info("Finished"); ac.close(); }
From source file:org.springframework.xd.gemfire.CacheServer.java
public static void main(String[] args) { if (args.length != 1) { System.out.println("Usage: CacheServer <config-file-path>"); System.exit(1);/* w w w. j a va 2 s . c o m*/ } String path = args[0]; if (!portAvailable(port)) { System.out.println("Cache Server port " + port + " is not available. Is another instance running?"); System.exit(1); } logger.info("Starting Cache Server"); @SuppressWarnings("resource") FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(path); context.registerShutdownHook(); Cache cache = context.getBean(Cache.class); ManagementService ms = ManagementService.getExistingManagementService(cache); CacheServerMXBean cacheServerManager = ms.getLocalCacheServerMXBean(port); if (!cacheServerManager.isRunning()) { System.out.println("failed to start cache server "); System.exit(1); } System.out.println("cache server running"); }
From source file:org.springframework.xd.gemfire.server.CacheServer.java
public static void main(String[] args) { if (args.length != 1) { System.out.println("Usage: CacheServer <config-file-path>"); System.exit(1);/*from ww w .j a v a 2 s . c o m*/ } /* * Ensure absolute path is handled */ String path = args[0]; if (!path.startsWith("file:")) { path = "file:" + path; } if (!portAvailable(port)) { System.out.println("Cache Server port " + port + " is not available. Is another instance running?"); System.exit(1); } logger.info("Starting Cache Server"); @SuppressWarnings("resource") FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(path); context.registerShutdownHook(); Cache cache = context.getBean(Cache.class); ManagementService ms = ManagementService.getExistingManagementService(cache); CacheServerMXBean cacheServerManager = ms.getLocalCacheServerMXBean(port); if (!cacheServerManager.isRunning()) { System.out.println("failed to start cache server "); System.exit(1); } System.out.println("cache server running"); }
From source file:pl.edu.icm.cermine.evaluation.AbstractEvaluator.java
public static void main(String programName, String[] args, String defaultConfigPath) throws AnalysisException, IOException, TransformationException { Options options = new Options(); options.addOption("compact", false, "do not print results for pages"); options.addOption("config", true, "use given evaluator configuration file"); options.addOption("help", false, "print this help message"); options.addOption("minimal", false, "print only final summary"); CommandLineParser parser = new GnuParser(); try {/* w w w .j a v a 2 s . c o m*/ CommandLine line = parser.parse(options, args); if (line.hasOption("help")) { HelpFormatter formatter = new HelpFormatter(); formatter.printHelp(programName + " [-options] input-directory [output-directory]", options); } else { String[] remaining = line.getArgs(); if (remaining.length == 0) { throw new ParseException("Missing input directory."); } if (remaining.length > 2) { throw new ParseException("Too many arguments."); } ApplicationContext context; if (line.hasOption("config")) { String path = line.getOptionValue("config"); if (new File(path).isAbsolute()) { path = "file:" + path; } context = new FileSystemXmlApplicationContext(path); } else { context = new ClassPathXmlApplicationContext(defaultConfigPath); } AbstractEvaluator evaluator = (AbstractEvaluator) context.getBean("evaluator"); if (line.hasOption("minimal")) { evaluator.detail = Detail.MINIMAL; } else if (line.hasOption("compact")) { evaluator.detail = Detail.COMPACT; } evaluator.run(remaining[0], remaining.length > 1 ? remaining[1] : null); } } catch (ParseException ex) { System.out.println("Parsing failed. Reason: " + ex.getMessage()); } }
From source file:uk.ac.ebi.phenotype.solr.indexer.AbstractIndexer.java
protected ApplicationContext loadApplicationContext(String context) { ApplicationContext appContext;/*from w w w . j a v a 2 s . c om*/ // Try context as a file resource. File file = new File(context); if (file.exists()) { // Try context as a file resource getLogger().info("Trying to load context from file system file {} ...", context); appContext = new FileSystemXmlApplicationContext("file:" + context); } else { // Try context as a class path resource getLogger().info("Trying to load context from classpath file: {}... ", context); appContext = new ClassPathXmlApplicationContext(context); } getLogger().info("Context loaded"); return appContext; }
From source file:uk.ac.ebi.phenotype.solr.indexer.IndexerManager.java
protected ApplicationContext loadApplicationContext(String context) { ApplicationContext appContext;//from w ww. j av a2s. c o m // Try context as a file resource. File file = new File(context); if (file.exists()) { // Try context as a file resource getLogger().info("Trying to load context from file system file {} ...", context); appContext = new FileSystemXmlApplicationContext("file:" + context); } else { // Try context as a class path resource // logger.info(TestUtils.getClasspath()); logger.info("Trying to load context from classpath file: {}... ", context); appContext = new ClassPathXmlApplicationContext(context); } getLogger().info("Context loaded"); return appContext; }