List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext getBean
@Override public Object getBean(String name) throws BeansException
From source file:com.himanshu.spring.context.loader.diffconfigpercontext.RunMe.java
public static void main(String[] args) { ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( "classpath:/diff-config-per-context/context/applicationContext.xml"); ServiceFactoryDiffConfigPerContext svcRepo = appContext.getBean(ServiceFactoryDiffConfigPerContext.class); DummyBean dummyBean_Context1 = svcRepo.getBean(DummyBean.class, "context1"); logger.info("From Dummy Bean in ctx1 : " + dummyBean_Context1.getWelcomeMsg()); DummyBean dummyBean_Context2 = svcRepo.getBean(DummyBean.class, "context2"); logger.info("From Dummy Bean in ctx2 : " + dummyBean_Context2.getWelcomeMsg()); appContext.destroy();// ww w .j a v a 2s . co m }
From source file:com.himanshu.spring.context.loader.sameconfigallcontext.RunMe.java
public static void main(String[] args) { ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext( "classpath:/same-config-all-context/context/applicationContext.xml"); ServiceFactorySameConfigAllContext svcRepo = appContext.getBean(ServiceFactorySameConfigAllContext.class); DummyBean dummyBean_Context1 = svcRepo.getBean(DummyBean.class, "context1"); logger.info("From Dummy Bean in ctx1 : " + dummyBean_Context1.getWelcomeMsg()); DummyBean dummyBean_Context2 = svcRepo.getBean(DummyBean.class, "context2"); logger.info("From Dummy Bean in ctx2 : " + dummyBean_Context2.getWelcomeMsg()); appContext.destroy();/* w ww . j av a2 s. c o m*/ }
From source file:sk.stefan.projekt.cxf.CxfApp.java
public static void main(String[] args) throws Exception { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( "classpath:/context/CXFContext.xml"); CxfApp cxf = (CxfApp) ctx.getBean("cxfApp"); MsgSender sender = (MsgSender) ctx.getBean("msgSenderClient"); MsgWrapper wrap = new MsgWrapper(); wrap.setMsg("KOKOSKO"); wrap.setQueue("queue1"); sender.sendMessage(wrap);//from w w w. j a v a2 s. c om }
From source file:org.seedstack.spring.batch.fixtures.FlatFileBatchDemo.java
public static void main(String[] argv) throws Exception { String jobFile = argv[0];//from w w w . jav a2 s . c om ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( new String[] { "simple-job-launcher-context.xml", jobFile }); Job job = applicationContext.getBean(Job.class); Map<String, JobParameter> jobParametersMap = new HashMap<>(); jobParametersMap.put("file", new JobParameter(argv[1])); JobParameters jobParameters = new JobParameters(jobParametersMap); JobLauncher jobLauncher = applicationContext.getBean(JobLauncher.class); JobExecution jobExecution = jobLauncher.run(job, jobParameters); printStatistics(jobExecution); }
From source file:tetrad.rrd.TestInstallTotalData.java
public static void main(String[] args) { String[] configLocations = new String[] { "applicationContext_rrd.xml" }; ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(configLocations); TetradRrdInitializer tetradInitial = (TetradRrdInitializer) context.getBean("tetradRrdInitializer"); DeviceInMemory deviceInMemory = (DeviceInMemory) context.getBean("deviceInMemory"); MongoInMemory mongoInMemory = (MongoInMemory) context.getBean("mongoInMemory"); try {/* ww w.j a v a 2 s. co m*/ deviceInMemory.createDeviceGroup(); mongoInMemory.createMongoGroup(); String poolSize = TetradRrdConfig.getTetradRrdConfig("default_rrdPoolSize"); TetradRrdDbPool.setPoolCount(Integer.parseInt(poolSize)); // tetradInitial.installTotalRrdDb(); tetradInitial.install(); // tetradInitial.input(); // TestInstallTotalData a = new TestInstallTotalData(); // a.initaillTotalRrd(); } catch (Exception e) { System.out.println("install error"); } }
From source file:demo.order.client.Client.java
public static void main(String args[]) throws Exception { // START SNIPPET: client ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "demo/order/client/client-beans.xml" }); OrderProcess client = (OrderProcess) context.getBean("orderClient"); OrderProcessClientHandler clientInterceptor = new OrderProcessClientHandler(); clientInterceptor.setUserName("John"); clientInterceptor.setPassword("password"); org.apache.cxf.endpoint.Client cxfClient = ClientProxy.getClient(client); cxfClient.getOutInterceptors().add(clientInterceptor); Order order = new Order(); order.setCustomerID("C001"); order.setItemID("I001"); order.setQty(100);// w w w . j a v a 2 s . com order.setPrice(200.00); String orderID = client.processOrder(order); String message = (orderID == null) ? "Order not approved" : "Order approved; order ID is " + orderID; System.out.println(message); System.exit(0); }
From source file:com.alibaba.dubbo.examples.cache.CacheConsumer.java
public static void main(String[] args) throws Exception { String config = CacheConsumer.class.getPackage().getName().replace('.', '/') + "/cache-consumer.xml"; ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(config); context.start();/*from w w w. jav a 2 s .c om*/ CacheService cacheService = (CacheService) context.getBean("cacheService"); // ?(?) String fix = null; for (int i = 0; i < 5; i++) { String result = cacheService.findCache("0"); if (fix == null || fix.equals(result)) { System.out.println("OK: " + result); } else { System.err.println("ERROR: " + result); } fix = result; Thread.sleep(500); } // LRU?cache.size10001001 for (int n = 0; n < 1001; n++) { String pre = null; for (int i = 0; i < 10; i++) { String result = cacheService.findCache(String.valueOf(n)); if (pre != null && !pre.equals(result)) { System.err.println("ERROR: " + result); } pre = result; } } // LRU String result = cacheService.findCache("0"); System.out.println("OK--->: " + result); if (fix != null && !fix.equals(result)) { System.out.println("OK: " + result); } else { System.err.println("ERROR: " + result); } }
From source file:org.excalibur.fm.configuration.Main.java
@SuppressWarnings("resource") public static void main(String[] args) throws InterruptedException { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "classpath*:META-INF/applicationContext.xml"); final ProviderService providerService = context.getBean(ProviderService.class); configureLookAndFeel();/* ww w . ja v a2s. co m*/ final JFrame frame = new JFrame(); frame.getContentPane().add(new InstanceSelectionPanel(providerService)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // frame.pack(); frame.setSize(1118, 470); frame.setLocationRelativeTo(null); java.awt.EventQueue.invokeLater(new Runnable() { public void run() { frame.setVisible(true); } }); // Thread.currentThread().join(); // context.close(); }
From source file:com.apress.prospringintegration.endpoints.consumerendpointfactory.Main.java
public static void main(String[] args) { ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext( "consumer-endpoint-factory.xml"); applicationContext.start();/*from w ww . j a va 2 s . c om*/ ProblemReporter problemReporter = applicationContext.getBean(ProblemReporter.class); TicketGenerator ticketGenerator = applicationContext.getBean(TicketGenerator.class); List<Ticket> tickets = ticketGenerator.createTickets(); int count = 0; while (count++ < 5) { for (Ticket ticket : tickets) { problemReporter.openTicket(ticket); } } }
From source file:org.excalibur.fm.configuration.Main2.java
public static void main(String[] args) { ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "classpath*:META-INF/applicationContext.xml"); ProviderService providerService = context.getBean(ProviderService.class); // get all instance types offered at the North America region of all providers List<InstanceType> instanceTypes = providerService .getInstanceTypesAvailableOnRegion(GeographicRegions.NORTH_AMERICA.toType()); // get all instance types of all regions of all providers instanceTypes = providerService.getAllInstanceTypesOfAllRegions(); Constraint[] constraints = new Constraint[] { new Constraint(new Variable("cores", 9), Operator.GE), new Constraint(new Variable("memory", 8 * 1024), Operator.GE), new Constraint(new Variable("cost", 1000), Operator.LE) }; List<InstanceType> allOptimalSolutions = new InstanceSelection2(instanceTypes) .findAllOptimalSolutions(constraints); System.out.format("\n%33s%17s%33s\n\n", " ", "Optimal solutions", " "); print(allOptimalSolutions);/* w w w .j a va 2s . c o m*/ context.close(); }