List of usage examples for org.springframework.context ConfigurableApplicationContext getBean
Object getBean(String name) throws BeansException;
From source file:com.all.ultrapeer.UltrapeerService.java
public static void main(String[] args) throws IOException { String[] configLocations = new String[] { "/applicationContext.xml" }; ConfigurableApplicationContext applicationContext = new ClassPathXmlApplicationContext(configLocations); UltrapeerService ultraPeerService = applicationContext.getBean(UltrapeerService.class); ServiceInvoker monitorable = applicationContext.getBean(ServiceInvoker.class); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); runInteractiveMode(applicationContext, ultraPeerService, monitorable, in); System.exit(0);//from w w w . j a v a 2 s. co m }
From source file:org.onebusaway.nyc.vehicle_tracking.utility.SensorModelVerificationMain.java
public static void main(String[] args) throws ParseException, ClassNotFoundException, CsvEntityIOException, IOException { Options options = new Options(); options.addOption(ARG_RULE, true, "sensor model rule class"); GnuParser parser = new GnuParser(); CommandLine cli = parser.parse(options, args); args = cli.getArgs();/* w w w . ja va2 s. c o m*/ if (args.length != 2) { System.err.println("usage: data-sources.xml tracesPath"); System.exit(-1); } ConfigurableApplicationContext context = ContainerLibrary.createContext( "classpath:org/onebusaway/nyc/vehicle_tracking/application-context.xml", "classpath:org/onebusaway/transit_data_federation/application-context.xml", args[0]); SensorModelVerificationMain m = new SensorModelVerificationMain(); context.getAutowireCapableBeanFactory().autowireBean(m); Collection<SensorModelRule> rules = Collections.emptyList(); if (cli.hasOption(ARG_RULE)) { Class<?> ruleClass = Class.forName(cli.getOptionValue(ARG_RULE)); rules = Arrays.asList((SensorModelRule) context.getBean(ruleClass)); } else { Map<String, SensorModelRule> rulesByName = context.getBeansOfType(SensorModelRule.class); rules = rulesByName.values(); } m.setRules(rules); File tracePath = new File(args[1]); List<File> traces = new ArrayList<File>(); getAllTraces(tracePath, traces); m.setTraces(traces); try { m.run(); } catch (Throwable ex) { ex.printStackTrace(); System.exit(-1); } System.exit(0); }
From source file:org.cbioportal.database.DatabaseAnnotator.java
private static void launchJob(String[] args, String isoform, String studies) throws Exception { SpringApplication app = new SpringApplication(DatabaseAnnotator.class); ConfigurableApplicationContext ctx = app.run(args); JobLauncher jobLauncher = ctx.getBean(JobLauncher.class); JobParameters jobParameters = new JobParametersBuilder().addString("isoform", isoform) .addString("studies", studies).toJobParameters(); Job databaseAnnotatorJob = ctx.getBean(BatchConfiguration.DATABASE_ANNOTATOR_JOB, Job.class); JobExecution jobExecution = jobLauncher.run(databaseAnnotatorJob, jobParameters); ctx.close();/*from ww w. j a v a2s . c om*/ }
From source file:org.kew.rmf.core.CoreApp.java
/** * Get the "engine" bean from the Spring config - Spring has instantiated it * with the values set in the application-context file, which defaults to * deduplication mode. If the context provided is a matching one, the bean * definition will be changed prior to its initialisation. * @param context/*w ww. java 2 s. c o m*/ * @throws Exception */ protected static void runEngineAndCache(ConfigurableApplicationContext context) throws Exception { DataHandler<?> engine = (DataHandler<?>) context.getBean("engine"); // Call the run method engine.run(); }
From source file:org.cbio.portal.pipelines.FoundationPipeline.java
private static void launchJob(String[] args, String sourceDirectory, String outputDirectory, String cancerStudyId, boolean generateXmlDocument) throws Exception { // set up application context and job launcher SpringApplication app = new SpringApplication(FoundationPipeline.class); ConfigurableApplicationContext ctx = app.run(args); JobLauncher jobLauncher = ctx.getBean(JobLauncher.class); // get the appropriate job name String jobName = generateXmlDocument ? BatchConfiguration.FOUNDATION_XML_DOCUMENT_JOB : BatchConfiguration.FOUNDATION_JOB; // configure job parameters and launch job Job foundationJob = ctx.getBean(jobName, Job.class); JobParameters jobParameters = new JobParametersBuilder().addString("sourceDirectory", sourceDirectory) .addString("outputDirectory", outputDirectory).addString("cancerStudyId", cancerStudyId) .toJobParameters();/*from w w w. j a va 2s . co m*/ JobExecution jobExecution = jobLauncher.run(foundationJob, jobParameters); // close job after completion LOG.info("Closing FoundationPipeline."); ctx.close(); }
From source file:com.acapulcoapp.alloggiatiweb.AddRegion.java
private static void initBeans(ConfigurableApplicationContext context) { countryRepository = context.getBean(CountryRepository.class); districtRepository = context.getBean(DistrictRepository.class); identityDocumentRepository = context.getBean(IdentityDocumentRepository.class); personRepository = context.getBean(PersonRepository.class); checkinTypeRepository = context.getBean(CheckinTypeRepository.class); checkinRecordRepository = context.getBean(CheckinRecordRepository.class); }
From source file:org.fcrepo.migration.handlers.BasicObjectVersionHandlerIT.java
@BeforeClass public static void migrateTestData() throws XMLStreamException { final ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("spring/it-setup.xml"); ((Migrator) context.getBean("f3Migrator")).run(); ((Migrator) context.getBean("f2Migrator")).run(); client = (Fedora4Client) context.getBean("fedora4Client"); idMapper = (MigrationIDMapper) context.getBean("idMapper"); context.close();/* ww w. j a v a 2s .c om*/ }
From source file:nl.tranquilizedquality.itest.jonas.TestAppJOnasNoDbDeploymentTest.java
@BeforeClass public static void runOnce() throws Exception { // The application server need to be locally started only if the // host is localhost if (StringUtils.contains(host, "localhost") || StringUtils.contains(host, "127.0.0.")) { if (log.isInfoEnabled()) { log.info("Starting up the container utility..."); }//www . j ava 2 s.c om final ConfigurableApplicationContext context = loadContext( new String[] { "jonas-itest-context.xml", "common-itest-context.xml" }); CONTAINER_UTIL = (ContainerUtil) context.getBean("containerUtil"); CONTAINER_UTIL.start(); } }
From source file:com.github.mrstampy.gameboot.GameBoot.java
private static void generatePropertyFiles(ConfigurableApplicationContext ctx) throws IOException { GameBootDependencyWriter writer = ctx.getBean(GameBootDependencyWriter.class); writer.writeDependencies(ctx);/*from w w w . j av a 2 s .c om*/ ctx.close(); }
From source file:com.wandrell.example.swss.client.console.ConsoleClient.java
/** * Returns a client generated from the Spring context defined in the * specified file.// w w w . j av a 2 s .c o m * * @param contextPath * path to the Spring context file * @return a client loaded from the specified context */ private static final EntityClient getEntityClient(final String contextPath) { final ConfigurableApplicationContext context; // Context final EntityClient client; // Client context = new ClassPathXmlApplicationContext(contextPath); client = context.getBean(EntityClient.class); context.close(); return client; }