List of usage examples for org.springframework.context.support AbstractApplicationContext getBean
@Override public <T> T getBean(Class<T> requiredType, Object... args) throws BeansException
From source file:com.japp.Main.java
/** * Load the Spring Integration Application Context * * @param args - command line arguments/*from w w w. ja v a2s . c o m*/ */ public static void main(final String... args) { if (LOGGER.isInfoEnabled()) { LOGGER.info("\n=========================================================" + "\n " + "\n SFTP-File Transfer POC " + "\n " + "\n========================================================="); } final AbstractApplicationContext context = new ClassPathXmlApplicationContext( "classpath:/launch-context.xml"); context.registerShutdownHook(); SpringIntegrationUtils.displayDirectories(context); final Scanner scanner = new Scanner(System.in); JobLauncher jobLauncher = context.getBean("jobLauncher", JobLauncher.class); Job job = context.getBean("job1", Job.class); try { jobLauncher.run(job, new JobParameters()); } catch (JobExecutionAlreadyRunningException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (JobRestartException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (JobInstanceAlreadyCompleteException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } catch (JobParametersInvalidException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } 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); }
From source file:org.mulima.internal.freedb.FreeDbImport.java
/** * Initializes the app.//from ww w . j a v a 2s .co m */ public void init() { AbstractApplicationContext context = new ClassPathXmlApplicationContext("importContext.xml"); context.registerShutdownHook(); jdbcDao = context.getBean("jdbcDao", FreeDbDao.class); tarDao = context.getBean("tarDao", FreeDbDao.class); }
From source file:org.apache.camel.example.spring.javaconfig.IntegrationTest.java
@Test public void testStartApplicationContext() throws Exception { // test to boot up the application context from spring configuration AbstractApplicationContext context = new ClassPathXmlApplicationContext( "/META-INF/spring/camel-context.xml"); String[] names = context.getBeanNamesForType(CamelContext.class); assertEquals("There should be a camel context ", 1, names.length); CamelContext camelContext = context.getBean(names[0], CamelContext.class); assertNotNull(camelContext);// w ww . j a v a2s . c om Thread.sleep(2000); // we're done so let's properly close the application context IOHelper.close(context); }
From source file:org.springframework.integration.samples.helloworld.HelloWorldApp.java
public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext( "/META-INF/spring/integration/helloWorldDemo.xml", HelloWorldApp.class); MessageChannel inputChannel = context.getBean("inputChannel", MessageChannel.class); PollableChannel outputChannel = context.getBean("outputChannel", PollableChannel.class); inputChannel.send(new GenericMessage<String>("World")); logger.info("==> HelloWorldDemo: " + outputChannel.receive(0).getPayload()); context.close();/* w w w.j a v a2 s . c om*/ }