List of usage examples for org.springframework.context ApplicationContext getBean
Object getBean(String name) throws BeansException;
From source file:koper.demo.main.SendMsgDemo.java
public static void main(String[] args) { final ApplicationContext context = new ClassPathXmlApplicationContext( "classpath:kafka/context-data-producer.xml"); final MemberService memberService = context.getBean(MemberService.class); Member member = new Member(); member.setName("LeBron James"); member.setPhoneNo("15097300863"); memberService.signup(member);/* w w w .j ava 2 s . co m*/ }
From source file:to.sparks.mtgox.example.PlaceOrders.java
public static void main(String[] args) throws Exception { // Obtain a $USD instance of the API ApplicationContext context = new ClassPathXmlApplicationContext("to/sparks/mtgox/example/Beans.xml"); MtGoxHTTPClient mtgoxUSD = (MtGoxHTTPClient) context.getBean("mtgoxUSD"); // Obtain information about the base currency of the API instance CurrencyInfo currencyInfo = mtgoxUSD.getCurrencyInfo(mtgoxUSD.getBaseCurrency()); logger.log(Level.INFO, "Base currency: {0}", currencyInfo.getCurrency().getCurrencyCode()); // Purchase 1.0 bitcoins for USD$0.01 MtGoxFiatCurrency fiatUnit = new MtGoxFiatCurrency(0.01D, currencyInfo); // We use the currencyInfo to be explicit about what this money represents MtGoxBitcoin bitcoinUnit = new MtGoxBitcoin(1.0D); // You should probably use BigDecimals instead of double types to represent money. String orderRef = mtgoxUSD.placeOrder(MtGoxHTTPClient.OrderType.Bid, fiatUnit, bitcoinUnit); logger.log(Level.INFO, "orderRef: {0}", new Object[] { orderRef }); // Cancel the order mtgoxUSD.cancelOrder(MtGoxHTTPClient.OrderType.Bid, orderRef); }
From source file:cl.bbr.servicemix.ServiceMixEmbebbed.Main.java
/** * @param args/* w w w . j a va 2 s .c om*/ */ public static void main(String[] args) { // This is a very simple example of how you might embed ServiceMix try { final ApplicationContext context = new ClassPathXmlApplicationContext("context-jbi.xml"); SpringJBIContainer container = (SpringJBIContainer) context.getBean("jbi"); container.onShutDown(new Runnable() { public void run() { if (context instanceof DisposableBean) { try { ((DisposableBean) context).destroy(); } catch (Exception e) { System.out.println("Caught: " + e); e.printStackTrace(); } } } }); } catch (Exception e) { System.out.println("Caught: " + e); e.printStackTrace(); } }
From source file:com.spring.tutorial.messages.App.java
public static void main(String[] args) { ApplicationContext ctx = new ClassPathXmlApplicationContext( "com/spring/tutorial/messages/applicationContext.xml"); MessageSource ms = ctx.getBean(MessageSource.class); //Message resolution String success = ms.getMessage("msg.success", null, Locale.getDefault()); String successEN = ms.getMessage("msg.success", null, Locale.ENGLISH); String successFR = ms.getMessage("msg.success", null, Locale.FRENCH); String successDE = ms.getMessage("msg.success", null, Locale.GERMAN); //Message resolution and i18n String label = ms.getMessage("lbl.result", null, Locale.getDefault()); //Not necessary to pass the locale String error = ms.getMessage("err.failure", null, null); //Non-existent message (if the call does not specify, the default message argument, //and the message code does not exist, an exception will be thrown) String nonExistent = ms.getMessage("my.message", null, "Not found, defaults to this message", null); LOGGER.info("Success message (es - the default): " + success); LOGGER.info("Success message (en): " + successEN); LOGGER.info("Success message (fr): " + successFR); LOGGER.info("Success message (de) defaults to local language: " + successDE); LOGGER.info("Label text: " + label); LOGGER.info("Error message: " + error); LOGGER.info("Non-existent message (defaults to message specified as argument): " + nonExistent); ((ClassPathXmlApplicationContext) ctx).close(); }
From source file:mx.gaby.test.Main.java
public static void main(String args[]) { System.out.println("..."); ApplicationContext applicationContext = new FileSystemXmlApplicationContext( "src/main/java/mx/gaby/test/config/app-config.xml"); TestService myClass = (TestService) applicationContext.getBean("testServiceImpl"); Contacto c = myClass.getContacto(2L); System.out.println("..." + c.getEmail()); }
From source file:com.dangdang.ddframe.rdb.sharding.example.config.spring.SpringNamespaceWithDefaultDataSourceMain.java
public static void main(final String[] args) throws SQLException { // CHECKSTYLE:ON ApplicationContext applicationContext = new ClassPathXmlApplicationContext( "META-INF/applicationContextWithDefaultDataSource.xml"); OrderService orderService = applicationContext.getBean(OrderService.class); orderService.insert();//from w w w.j a va 2 s.co m orderService.select(); orderService.delete(); orderService.select(); }
From source file:org.spc.ofp.tubs.importer.CopyFromObserver.java
/** * @param args// w ww . j a va 2s . c o m */ public static void main(final String[] args) throws Exception { // FIXME Add argument parsing. // FIXME With all the required libraries, will probably have to use Maven to execute final ApplicationContext ctx = new ClassPathXmlApplicationContext(SPRING_CONFIGS); ctx.getBean(CopyFromObserver.class).doCopy(); }
From source file:com.alacoder.lion.rpc.springsupport.DemoRpcClient.java
@SuppressWarnings({ "resource", "unused" }) public static void main(String[] args) throws InterruptedException { ApplicationContext applicationContext = new ClassPathXmlApplicationContext( new String[] { "classpath*:lion_demo_server.xml" }); System.out.println("server start..."); ApplicationContext ctx = new ClassPathXmlApplicationContext( new String[] { "classpath:lion_demo_client.xml" }); DemoService service = (DemoService) ctx.getBean("lionDemoReferer"); for (int i = 0; i < Integer.MAX_VALUE; i++) { System.out.println(service.hello("lion " + i)); Thread.sleep(1000);//from www. j a v a2 s. c om } System.out.println("lion demo is finish."); System.exit(0); }
From source file:com.bia.config.Main.java
public static void main(String[] args) throws Exception { ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/spring/applicationContext*.xml"); EmployeeCassandraServiceImpl service = context.getBean(EmployeeCassandraServiceImpl.class); Emp emp = new Emp(); emp.setId((new Date()).toString()); String username = "IM-" + new Date(); emp.setUsername(username);/*from w ww. j a v a 2 s . c o m*/ emp.setJoinDate(new Date()); emp.setStorageSize(10.0); emp.setContent(ByteBuffer .wrap(IOUtils.toByteArray(Main.class.getClassLoader().getResourceAsStream("log4j.properties")))); service.saveEmployee(emp); int count = 0; for (Emp e : service.findAllEmployees()) { System.out.println(e + String.valueOf(e.getContent())); System.out.println(new String(e.getContent().array())); count++; } System.out.println("done " + count); System.out.println(service.findByUsername(username)); }
From source file:org.learnSpring.DI.MainApp.java
public static void main(String[] args) { System.out.println("Initializing Spring context."); ApplicationContext applicationContext = new ClassPathXmlApplicationContext("/application-context.xml"); System.out.println("Spring context initialized."); Movie movie = (Movie) applicationContext.getBean("movie"); System.out.println("Movie details:'"); movie.showDetails();/*from ww w . ja v a2 s .c om*/ }