List of usage examples for org.springframework.context.support GenericApplicationContext getBean
@Override public <T> T getBean(String name, Class<T> requiredType) throws BeansException
From source file:com.apress.prospringintegration.springenterprise.stocks.runner.MainHibernateJPA.java
public static void main(String[] args) { GenericApplicationContext context = new AnnotationConfigApplicationContext( "com.apress.prospringintegration.springenterprise.stocks.dao.jpa"); StockDao stockDao = context.getBean("jpaStockDao", StockDao.class); Stock stock = new Stock("ORAC", "JPAMAIN0001", "QQQQ", 120.0f, 1100, Calendar.getInstance().getTime()); stockDao.insert(stock);// w w w. ja v a 2 s. com List<Stock> stocks = stockDao.findAvailableStockBySymbol("ORAC"); if (stocks != null && stocks.size() > 0) { stock = stocks.get(0); System.out.println("Stock Symbol :" + stock.getSymbol()); System.out.println("Inventory Code :" + stock.getInventoryCode()); System.out.println("purchased price:" + stock.getSharePrice()); System.out.println("Exchange ID:" + stock.getExchangeId()); System.out.println("Quantity Available :" + stock.getQuantityAvailable()); } }
From source file:com.apress.prospringintegration.springenterprise.stocks.runner.MainRmiClient.java
public static void main(String[] args) { GenericApplicationContext context = new AnnotationConfigApplicationContext( "com.apress.prospringintegration.springenterprise.stocks.client"); QuoteServiceClient client = context.getBean("client", QuoteServiceClient.class); List<Quote> myQuotes = new ArrayList<Quote>(); myQuotes.add(client.getMyQuote("APRESS")); myQuotes.add(client.getMyQuote("SPRNG")); myQuotes.add(client.getMyQuote("INTGRN")); for (Quote myQuote : myQuotes) { System.out.println("Symbol : " + myQuote.getSymbol()); System.out.println("Price :" + myQuote.getPrice()); System.out.println("Exchange: " + myQuote.getExchangeId()); }//from w w w . j a va2 s. co m }
From source file:com.apress.prospringintegration.springenterprise.stocks.runner.MainHibernate.java
public static void main(String[] args) { GenericApplicationContext context = new AnnotationConfigApplicationContext( "com.apress.prospringintegration.springenterprise.stocks.dao.hibernate"); StockDao stockDao = context.getBean("hibernateStockDao", StockDao.class); Stock stock = new Stock("ORAC", "HIBERNATEMAIN0001", "QQQQ", 120.0f, 1100, Calendar.getInstance().getTime()); stockDao.insert(stock);/*from w w w . java2s . com*/ stock = stockDao.findByInventoryCode("HIBERNATEMAIN0001"); if (stock != null) { System.out.println("Stock Symbol :" + stock.getSymbol()); System.out.println("Inventory Code :" + stock.getInventoryCode()); System.out.println("purchased price:" + stock.getSharePrice()); System.out.println("Exchange ID:" + stock.getExchangeId()); System.out.println("Quantity Available :" + stock.getQuantityAvailable()); } }
From source file:com.apress.prospringintegration.springenterprise.stocks.runner.MainJdbcTemplate.java
public static void main(String[] args) { GenericApplicationContext context = new AnnotationConfigApplicationContext( "com.apress.prospringintegration.springenterprise.stocks.dao.jdbc"); StockDao stockDao = context.getBean("jdbcTemplateStockDao", StockDao.class); Stock stock = new Stock("ORAC", "JDBCTPL0001", "QQQQ", 120.0f, 1100, Calendar.getInstance().getTime()); stockDao.insert(stock);/*from ww w.jav a 2 s.co m*/ stock = new Stock("APRS", "JDBCTPL0002", "QQQQ", 150.00F, 1500, Calendar.getInstance().getTime()); stockDao.insert(stock); stock = stockDao.findByInventoryCode("JDBCTPL0001"); if (stock != null) { System.out.println("Template Version"); System.out.println("Stock Symbol :" + stock.getSymbol()); System.out.println("Inventory Code :" + stock.getInventoryCode()); System.out.println("purchased price:" + stock.getSharePrice()); System.out.println("Exchange ID:" + stock.getExchangeId()); System.out.println("Quantity Available :" + stock.getQuantityAvailable()); } }
From source file:com.apress.prospringintegration.springenterprise.stocks.runner.MainHibernateEntityManager.java
public static void main(String[] args) { GenericApplicationContext context = new AnnotationConfigApplicationContext( "com.apress.prospringintegration.springenterprise.stocks.dao.jpaandentitymanagers"); StockDao stockDao = context.getBean("jpaStockDao", StockDao.class); Stock stock = new Stock("ORAC", "JPAMAIN0001", "QQQQ", 120.0f, 1100, Calendar.getInstance().getTime()); stockDao.insert(stock);//from www . j a va 2s. c o m List<Stock> stocks = stockDao.findAvailableStockBySymbol("ORAC"); if (stocks != null && stocks.size() > 0) { stock = stocks.get(0); System.out.println("Stock Symbol :" + stock.getSymbol()); System.out.println("Inventory Code :" + stock.getInventoryCode()); System.out.println("purchased price:" + stock.getSharePrice()); System.out.println("Exchange ID:" + stock.getExchangeId()); System.out.println("Quantity Available :" + stock.getQuantityAvailable()); } }
From source file:com.apress.prospringintegration.springenterprise.stocks.runner.MainTxAnnotation.java
public static void main(String[] args) throws Exception { GenericApplicationContext context = new AnnotationConfigApplicationContext( "com.apress.prospringintegration.springenterprise.stocks.transactions.annotation", "com.apress.prospringintegration.springenterprise.stocks.dao.hibernate"); StockBrokerService broker = context.getBean("annotationTxStockBrokerService", StockBrokerService.class); try {//www . ja v a 2s .c o m broker.preFillStocks("QQQQ", "INTC", "IBM", "XLA", "MGM", "C"); } catch (Exception ex) { System.out.println("Exception: " + ex.getMessage()); } StockDao stockDao = context.getBean(HibernateStockDao.class); System.out.println("Total rows inserted: " + stockDao.get().size()); for (Stock s : stockDao.get()) { System.out.println("Stock added: " + s.getSymbol()); } }
From source file:com.apress.prospringintegration.springenterprise.stocks.runner.MainTxAop.java
public static void main(String[] args) throws Exception { GenericApplicationContext context = new AnnotationConfigApplicationContext( "com.apress.prospringintegration.springenterprise.stocks.transactions.aopdeclarative", "com.apress.prospringintegration.springenterprise.stocks.dao.hibernate"); StockBrokerService broker = context.getBean("aopStockBrokerService", StockBrokerService.class); try {// w w w . jav a2 s . com broker.preFillStocks("QQQQ", "INTC", "IBM", "XLA", "MGM", "C"); } catch (Exception ex) { System.out.println("Exception: " + ex.getMessage()); } StockDao stockDao = context.getBean(HibernateStockDao.class); System.out.println("Total rows inserted: " + stockDao.get().size()); for (Stock s : stockDao.get()) { System.out.println("Stock added: " + s.getSymbol()); } }
From source file:com.apress.prospringintegration.springenterprise.stocks.runner.MainTxJdbc.java
public static void main(String[] args) { GenericApplicationContext context = new AnnotationConfigApplicationContext( "com.apress.prospringintegration.springenterprise.stocks.transactions.template", "com.apress.prospringintegration.springenterprise.stocks.dao.jdbc"); TransactionalStockBrokerService uStockDao = context.getBean("transactionalStockBrokerService", TransactionalStockBrokerService.class); try {// w ww . ja va 2s . co m uStockDao.preFillStocks("TEST", "IBM", "INTC", "MSFT", "ORAC", "C"); } catch (Exception ex) { System.out.println("Exception: " + ex.getMessage()); } StockDao stockDao = context.getBean(JdbcTemplateStockDao.class); System.out.println("Total rows inserted: " + stockDao.get().size()); for (Stock s : stockDao.get()) { System.out.println("Stock added: " + s.getSymbol()); } }
From source file:com.jaspersoft.jasperserver.export.RemoveDuplicatedDisplayName.java
public static void main(String[] args) { Parameters params = null;// ww w .j av a2s . c o m boolean success = false; try { GenericApplicationContext ctx = new GenericApplicationContext(); XmlBeanDefinitionReader configReader = new XmlBeanDefinitionReader(ctx); List resourceXML = getPaths(args[2]); if (args != null && args.length > 0) { for (int i = 0; i < resourceXML.size(); i++) { org.springframework.core.io.Resource resource = classPathResourceFactory .create((String) resourceXML.get(i)); configReader.loadBeanDefinitions(resource); } } ctx.refresh(); if (args.length > 3) { if ("UPDATE".equals(args[3])) { updateRepo = true; } } // write to file // try { CommandBean commandBean = (CommandBean) ctx.getBean("removeDuplicateDisplayName", CommandBean.class); Charset encoding = Charset.forName( ((RemoveDuplicatedDisplayName) commandBean).getEncodingProvider().getCharacterEncoding()); osw = new OutputStreamWriter(new FileOutputStream("remove_duplicated_display_name_report.txt"), encoding); commandBean.process(params); } finally { osw.close(); } success = true; } catch (Exception e) { e.printStackTrace(System.err); } System.exit(success ? 0 : -1); }
From source file:org.jboss.fuse.wsdl2rest.util.SpringCamelContextFactory.java
private static List<SpringCamelContext> createCamelContextList(Resource resource, ClassLoader classLoader) throws Exception { if (classLoader == null) classLoader = SpringCamelContextFactory.class.getClassLoader(); GenericApplicationContext appContext = new GenericApplicationContext(); appContext.setClassLoader(classLoader); XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appContext) { @Override/*from www .ja va 2 s . co m*/ protected NamespaceHandlerResolver createDefaultNamespaceHandlerResolver() { NamespaceHandlerResolver defaultResolver = super.createDefaultNamespaceHandlerResolver(); return new CamelNamespaceHandlerResolver(defaultResolver); } }; xmlReader.loadBeanDefinitions(resource); SpringCamelContext.setNoStart(true); appContext.refresh(); List<SpringCamelContext> result = new ArrayList<>(); for (String name : appContext.getBeanNamesForType(SpringCamelContext.class)) { result.add(appContext.getBean(name, SpringCamelContext.class)); } return Collections.unmodifiableList(result); }