List of usage examples for org.springframework.context.support AbstractApplicationContext getBean
@Override public <T> T getBean(Class<T> requiredType) throws BeansException
From source file:firstspring.FIRSTSPRING.java
/** * @param args the command line arguments *///from ww w. j a v a2 s. c om public static void main(String[] args) { final AbstractApplicationContext ctx = new ClassPathXmlApplicationContext( new String[] { "applicationContext.xml" }); OwnerService owner = (OwnerService) ctx.getBean("owner"); Animal pet = owner.getPet(); pet.speak(); }
From source file:com.delphix.appliance.host.example.server.ExampleServerLauncher.java
public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext(CONFIG_LOCATION); try {/*from w w w .ja va 2 s. c o m*/ final ExampleServer server = (ExampleServer) context.getBean("server"); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { server.fini(); } }); } finally { context.close(); } }
From source file:cn.com.inhand.devicenetworks.ap.mq.rabbitmq.TaskNotificationConsumer.java
public static void main(String[] agrs) throws Exception { String path = "file:/home/han/myworks/workroom/NetBeansProjects/WSAP/RabbitMQDemo/RabbitMQDemo/src/main/webapp/WEB-INF/MQXMLApplicationContext.xml"; AbstractApplicationContext ctx = new FileSystemXmlApplicationContext(path); RabbitTemplate template = ctx.getBean(RabbitTemplate.class); template.convertAndSend("Hello, world!"); Thread.sleep(1000);//from w ww . ja v a2 s . c o m ctx.destroy(); }
From source file:com.ushahidi.swiftriver.core.dropqueue.DropQueueProcessor.java
@SuppressWarnings("resource") public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext("appContext.xml"); context.registerShutdownHook();//from w w w . ja v a 2s.com DropFilterPublisher dropFilterPublisher = context.getBean(DropFilterPublisher.class); dropFilterPublisher.start(); logger.info("Drop queue processor started"); }
From source file:samples.ProducerApplication.java
public static void main(String[] args) { AbstractApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); context.registerShutdownHook();//w w w.j a v a2s. c o m SpringJmsProducer producer = (SpringJmsProducer) context.getBean("springJmsProducer"); producer.run(); ((org.springframework.jms.connection.CachingConnectionFactory) context.getBean("connectionFactory")) .resetConnection(); }
From source file:p1.PointDaoDemo.java
/** * @param args the command line arguments */// w ww . ja va 2 s . c o m public static void main(String[] args) { AbstractApplicationContext ac = new FileSystemXmlApplicationContext( "C:\\Users\\Bhushan\\Documents\\NetBeansProjects\\PointDAO\\src\\p1\\one.xml"); Point p1 = (Point) ac.getBean("pt"); PointDAO.insertPoint(p1); // The above operation demonstrates insert operation on the the class Point. Like wise we can perform //other operations like getPoint, delete point etc }
From source file:org.jboss.narayana.quickstart.spring.Launch.java
public static void main(String[] args) throws Exception { AbstractApplicationContext context = new AnnotationConfigApplicationContext( Launch.class.getPackage().getName()); ExampleService service = context.getBean(ExampleService.class); if (args.length == 1) { RecoveryManagerService recoveryManagerService = context.getBean(RecoveryManagerService.class); if (args[0].equals("-f")) { System.out.println("Generate something to recovery ..."); service.testRecovery();//from ww w . j a va2s .co m } else if (args[0].equals("-r")) { System.out.println("start the recovery manager"); recoveryManagerService.start(); System.out.println("recovery manager scan ..."); while (DummyXAResource.getCommitRequests() == 0) { Thread.sleep(1000); } System.out.println("stop the recovery manager"); recoveryManagerService.stop(); } else if (args[0].equals("-c")) { service.checkRecord(); } } else { service.testCommit(); service.checkRecord(); } service.shutdownDatabase(); TxControl.disable(true); TransactionReaper.terminate(true); }
From source file:jpa.JpaApplication.java
public static void main(String[] args) throws Exception { AbstractApplicationContext context = new AnnotationConfigApplicationContext(JpaConfig.class); final ThingControl tc = (ThingControl) context.getBean("thingControl"); Person user = new Person(); user.setFirstName("Person"); user.setLastName("Name"); Thing<Person> pt = tc.createThing("username", user); Address address = new Address(); address.setCity("Auckland"); address.setCountry("NZ"); address.setNr(1);//from w ww .j a v a 2 s . c o m address.setStreet("Fleet street"); Thing<Address> at = tc.createThing("home", address); tc.addChildThing(pt, at); Object id = pt.getId(); System.out.println("ID: " + id); Role role1 = new Role("role1"); Thing<Role> r1t = tc.createThing("group_1", role1); Role role2 = new Role("role2"); Thing<Role> r2t = tc.createThing("group_1", role2); Role role3 = new Role("role3"); Thing<Role> r3t = tc.createThing("group_2", role3); tc.addChildThing(pt, r1t); tc.addChildThing(pt, r2t); tc.addChildThing(pt, r3t); Observable<? extends Thing<?>> childs = tc.observeChildrenMatchingTypeAndKey(pt, "role", "*2*", true); childs.toBlockingObservable().forEach(t -> System.out.println(t)); Observable<? extends Thing<?>> childs2 = tc.observeChildrenMatchingTypeAndKey(pt, "address", "*", true); childs2.toBlockingObservable().forEach(t -> System.out.println(t)); }
From source file:org.trendafilov.odesk.notifier.Main.java
public static void main(String[] args) { @SuppressWarnings("resource") // context resource is closed via a shutdown hook AbstractApplicationContext context = new ClassPathXmlApplicationContext("notifier-app.xml"); context.registerShutdownHook();/*from www.j a v a 2 s .c om*/ Main app = context.getBean(Main.class); app.startup(); }
From source file:com.oreilly.springdata.hadoop.hive.HiveApp.java
public static void main(String[] args) throws Exception { AbstractApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/hive-context.xml", HiveApp.class); log.info("Hive Application Running"); context.registerShutdownHook();//from w ww .j ava2 s .c om HiveTemplate template = context.getBean(HiveTemplate.class); log.info(template.query("show tables;")); PasswordRepository repository = context.getBean(HiveTemplatePasswordRepository.class); repository.processPasswordFile("/etc/passwd"); log.info("Count of password entries = " + repository.count()); }