List of usage examples for org.springframework.context.support FileSystemXmlApplicationContext getBean
@Override
public Object getBean(String name) throws BeansException
From source file:infrascructure.data.StandaloneLauncher.java
/** * @param args// www .j a va2s. c o m */ public static void main(String[] args) { Trace.trace("starting .."); String appContextPath = null; if (args.length > 0) { appContextPath = args[0]; } String testConfigPath = appContextPath == null ? "src/main/resources/localSampleContext.xml" : appContextPath; String fullPath = new File(testConfigPath).getAbsolutePath(); Trace.trace("Configuration path: " + fullPath); FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(testConfigPath); StandaloneLauncher launcher = context.getBean(StandaloneLauncher.class); launcher.process(); }
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++;//from ww w . jav a2 s . c o m System.out.println(thesis.getContent()); } System.out.println(count); }
From source file:net.darkmist.alib.spring.Main.java
public static void main(String[] args) { FileSystemXmlApplicationContext ctx; Runnable mb;/*from w w w .j av a 2s . c om*/ boolean doExit = false; int exitCode = 0; if (args.length < 1) usage(); ctx = new FileSystemXmlApplicationContext(args[0]); mb = (Runnable) ctx.getBean(MAIN_BEAN); if (mb instanceof MainBean) ((MainBean) mb).setArgs(args, 1, args.length - 1); else if (args.length > 1) throw new IllegalArgumentException("main bean does not take arguments"); mb.run(); if (mb instanceof MainBean) { exitCode = ((MainBean) mb).getExitCode(); doExit = true; } mb = null; ctx.close(); if (doExit) System.exit(exitCode); }
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 w w w .j a va 2 s . com*/ 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.pontecultural.flashcards.ReadSpreadsheet.java
public static void main(String[] args) throws Exception { FileSystemXmlApplicationContext dbCtx = new FileSystemXmlApplicationContext( "src/main/webapp/WEB-INF/spring/appServlet/flashcards-persistence.xml"); JdbcFlashcardsDao jDao = (JdbcFlashcardsDao) dbCtx.getBean("jdbcFlashcardsDaoTest"); ReadSpreadsheet ods = new ReadSpreadsheet(); ods.setJdbcFlashcardsDao(jDao);/*from w w w . j av a 2s . co m*/ ods.setOdsFile("/home/jkern/workspace/JavaSpring/test/data/FlashCardsTest.ods"); ods.run(); }
From source file:de.uniwue.dmir.heatmap.EntryPointIncremental.java
@SuppressWarnings({ "rawtypes", "unchecked" })
public static void main(String[] args) throws IOException, ParseException {
DateFormat df = new SimpleDateFormat(DATE_FORMAT);
SimpleDateFormat backupDf = new SimpleDateFormat(BACKUP_DATE_FORMAT);
String workDir = System.getProperty("workDir", ".");
LOGGER.debug("Work dir: {}", workDir);
String configDir = System.getProperty("configDir", ".");
LOGGER.debug("Config dir: {}", configDir);
File seedDir = new File(workDir, SEED_DIR);
LOGGER.debug("Seed dir: {}", seedDir);
File currentDir = new File(workDir, CURRENT_DIR);
LOGGER.debug("Current dir: {}", currentDir);
File backupDir = new File(workDir, BACKUP_DIR);
LOGGER.debug("Backup dir: {}", backupDir);
String initialMinTimeString = System.getProperty("minTime");
LOGGER.debug("Initial minimal time parameter: {}", initialMinTimeString);
Date initialMinTime = initialMinTimeString == null ? new Date(0) : df.parse(initialMinTimeString);
LOGGER.debug("Initial minimal time: {}", df.format(initialMinTime));
String absoluteMaxTimeString = System.getProperty("maxTime");
LOGGER.debug("Absolute maximal time parameter: {}", absoluteMaxTimeString);
Date absoluteMaxTime = absoluteMaxTimeString == null ? new Date()
: new SimpleDateFormat(DATE_FORMAT).parse(absoluteMaxTimeString);
LOGGER.debug("Absolute maximal time: {}", df.format(absoluteMaxTime));
String incrementalFile = new File("file:" + configDir, INCREMENTAL_FILE).getPath();
String settingsFile = new File("file:" + configDir, HEATMAP_PROCESSOR__FILE).getPath();
LOGGER.debug("Initializing incremental control file: {}", incrementalFile);
FileSystemXmlApplicationContext incrementalContext = new FileSystemXmlApplicationContext(incrementalFile);
// get point limit
int pointLimit = Integer
.parseInt(incrementalContext.getBeanFactory().resolveEmbeddedValue("${point.limit}"));
LOGGER.debug("Print limit: {}", pointLimit);
// get backups to keep
int backupsToKeep = Integer
.parseInt(incrementalContext.getBeanFactory().resolveEmbeddedValue("${backups.to.keep}"));
LOGGER.debug("Backups to keep: {}", pointLimit);
LOGGER.debug("Initializing process components (manager and limiter).");
IProcessManager processManager = incrementalContext.getBean(IProcessManager.class);
IProcessLimiter processLimiter = incrementalContext.getBean(IProcessLimiter.class);
LOGGER.debug("Starting incremental loop.");
while (true) { // break as soon as no new points are available
// cleanup --- just in case
LOGGER.debug("Deleting \"current\" dir.");
FileUtils.deleteDirectory(currentDir);
// copy from seed to current
LOGGER.debug("Copying seed.");
seedDir.mkdirs();/*from w w w . j a va2 s .c o m*/
FileUtils.copyDirectory(seedDir, currentDir);
// get min time
LOGGER.debug("Getting minimal time ...");
Date minTime = initialMinTime;
ProcessManagerEntry entry = processManager.getEntry();
if (entry != null && entry.getMaxTime() != null) {
minTime = entry.getMaxTime();
}
LOGGER.debug("Minimal time: {}", new SimpleDateFormat(DATE_FORMAT).format(minTime));
// break if we processed all available points (minTime is greater than or equal to absoluteMaxTime)
if (minTime.getTime() >= absoluteMaxTime.getTime()) {
LOGGER.debug("Processed all points.");
break;
}
// get the maximal time
LOGGER.debug("Get maximal time.");
// get the time from the newest point in our point range (pointMaxTime) ...
Date pointMaxTime = processLimiter.getMaxTime(minTime, pointLimit);
// ... and possibly break the loop if no new points are available
if (pointMaxTime == null)
break;
// set the max time and make sure we are not taking to many points
// (set max time to the minimum of pointMaxTime and absoluteMaxTime)
Date maxTime = pointMaxTime.getTime() > absoluteMaxTime.getTime() ? absoluteMaxTime : pointMaxTime;
LOGGER.debug("Maximal time: {}", new SimpleDateFormat(DATE_FORMAT).format(maxTime));
// start process
processManager.start(minTime);
System.setProperty("minTimestamp", new SimpleDateFormat(DATE_FORMAT).format(minTime));
System.setProperty("maxTimestamp", new SimpleDateFormat(DATE_FORMAT).format(maxTime));
FileSystemXmlApplicationContext heatmapContext = new FileSystemXmlApplicationContext(settingsFile);
IHeatmap heatmap = heatmapContext.getBean(HEATMAP_BEAN, IHeatmap.class);
ITileProcessor tileProcessor = heatmapContext.getBean(WRITER_BEAN, ITileProcessor.class);
heatmap.processTiles(tileProcessor);
tileProcessor.close();
heatmapContext.close();
// finish process
processManager.finish(maxTime);
// move old seed
if (backupsToKeep > 0) {
FileUtils.moveDirectory(seedDir, new File(backupDir, backupDf.format(minTime))); // minTime is the maxTime of the seed
// cleanup backups
String[] backups = backupDir.list(DirectoryFileFilter.DIRECTORY);
File oldestBackup = null;
if (backups.length > backupsToKeep) {
for (String bs : backups) {
File b = new File(backupDir, bs);
if (oldestBackup == null || oldestBackup.lastModified() > b.lastModified()) {
oldestBackup = b;
}
}
FileUtils.deleteDirectory(oldestBackup);
}
} else {
FileUtils.deleteDirectory(seedDir);
}
// move new seed
FileUtils.moveDirectory(currentDir, seedDir);
}
incrementalContext.close();
}
From source file:org.craftercms.cstudio.publishing.PublishingReceiverMain.java
private static Server initializeContext() throws IOException { System.setProperty("org.terracotta.quartz.skipUpdateCheck", "true"); FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext( "classpath:spring/application-context.xml"); Server server = (Server) context.getBean("Server"); context.close();/*from w ww . j a v a 2s. co m*/ return server; }
From source file:org.apache.ftpserver.main.Daemon.java
/** * Get the configuration object.//from ww w. ja v a 2s . c o m */ private static FtpServer getConfiguration(String[] args) throws Exception { FtpServer server = null; if (args == null || args.length < 2) { LOG.info("Using default configuration...."); server = new FtpServerFactory().createServer(); } else if ((args.length == 2) && args[1].equals("-default")) { // supported for backwards compatibility, but not documented System.out.println("The -default switch is deprecated, please use --default instead"); LOG.info("Using default configuration...."); server = new FtpServerFactory().createServer(); } else if ((args.length == 2) && args[1].equals("--default")) { LOG.info("Using default configuration...."); server = new FtpServerFactory().createServer(); } else if (args.length == 2) { LOG.info("Using xml configuration file " + args[1] + "..."); FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(args[1]); if (ctx.containsBean("server")) { server = (FtpServer) ctx.getBean("server"); } else { String[] beanNames = ctx.getBeanNamesForType(FtpServer.class); if (beanNames.length == 1) { server = (FtpServer) ctx.getBean(beanNames[0]); } else if (beanNames.length > 1) { System.out .println("Using the first server defined in the configuration, named " + beanNames[0]); server = (FtpServer) ctx.getBean(beanNames[0]); } else { System.err.println("XML configuration does not contain a server configuration"); } } } else { throw new FtpException("Invalid configuration option"); } return server; }
From source file:org.apache.smscserver.main.Daemon.java
/** * Get the configuration object./*w ww. ja v a 2 s. c om*/ */ private static SmscServer getConfiguration(String[] args) throws Exception { SmscServer server = null; if ((args == null) || (args.length < 2)) { Daemon.LOG.info("Using default configuration...."); server = new SmscServerFactory().createServer(); } else if ((args.length == 2) && args[1].equals("-default")) { // supported for backwards compatibility, but not documented System.out.println("The -default switch is deprecated, please use --default instead"); Daemon.LOG.info("Using default configuration...."); server = new SmscServerFactory().createServer(); } else if ((args.length == 2) && args[1].equals("--default")) { Daemon.LOG.info("Using default configuration...."); server = new SmscServerFactory().createServer(); } else if (args.length == 2) { Daemon.LOG.info("Using xml configuration file " + args[1] + "..."); FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(args[1]); if (ctx.containsBean("server")) { server = (SmscServer) ctx.getBean("server"); } else { String[] beanNames = ctx.getBeanNamesForType(SmscServer.class); if (beanNames.length == 1) { server = (SmscServer) ctx.getBean(beanNames[0]); } else if (beanNames.length > 1) { System.out .println("Using the first server defined in the configuration, named " + beanNames[0]); server = (SmscServer) ctx.getBean(beanNames[0]); } else { System.err.println("XML configuration does not contain a server configuration"); } } } else { throw new SmscException("Invalid configuration option"); } return server; }
From source file:com.snp.site.init.SystemInit.java
public static void initSystemStaitcData(ServletContextEvent sce) { try {//from w w w . j a v a 2s . c o m // siteStrMap = getMapFromePropFile(getClassPath() + "/lang", // "txt"); // snpStrMap = getMapFromePropFile(getClassPath() + "/lang", "txt"); FtpServer ftpserver = null; String config = "conf/ftp/conf/ftpd-typical.xml"; FileSystemXmlApplicationContext ctx = new FileSystemXmlApplicationContext(config); String[] beanNames = ctx.getBeanNamesForType(FtpServer.class); ftpserver = (FtpServer) ctx.getBean(beanNames[0]); ftpserver.start(); DefaultFtpServer defaultFtpServer = (DefaultFtpServer) ftpserver; System.out.println(defaultFtpServer); // PropertiesUserManager propertiesUserManager = // (PropertiesUserManager) defaultFtpServer.getUserManager(); SystemInit.serverFtp = defaultFtpServer; } catch (Exception e) { log.error("", e); } }