List of usage examples for org.springframework.context.support ClassPathXmlApplicationContext ClassPathXmlApplicationContext
public ClassPathXmlApplicationContext(String... configLocations) throws BeansException
From source file:com.qrmedia.commons.aspect.example.AdviceDemo.java
public static void main(String[] args) { Log log = LogFactory.getLog(AdviceDemo.class); AdvisedObject advisedObject = (AdvisedObject) new ClassPathXmlApplicationContext(CONTEXT_FILENAMES) .getBean("advisedBean"); log.info("Calling a traced method..."); advisedObject.tracedMethod("James Bond", 7, "License to Kill".getBytes()); log.info("Calling a traced method that returns a result..."); log.info("Result: " + advisedObject.resultReturningTracedMethod(6)); log.info("Calling a profiled method..."); advisedObject.profiledMethod();/*from w w w . j a va2 s. c om*/ }
From source file:com.geas.blog.blog.App.java
License:asdf
public static void main(String[] args) { System.out.println("load context"); ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); Post testPost = new Post(); testPost.setPostId(1);/*from w ww .java 2 s.c o m*/ testPost.setTitle("John"); testPost.setBody("l;asdfja;lsdkfj;ladsfj;l;ldkskfja;sldfkja;lsdfjaf;lfdjkas;dlfja;ldsfkja;dlfk"); PostDBService testPostService = (PostDBService) context.getBean("postService"); testPostService.persistPost(testPost); System.out.println("Updated title :" + testPostService.findPostById(1).getTitle()); testPost.setTitle("Hello"); testPostService.updatePost(testPost); System.out.println("Updated title :" + testPostService.findPostById(1).getTitle()); testPostService.deletePost(testPost); context.close(); }
From source file:tpoint.spring.log4j.TutorialsPoint.java
public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml"); log.info("Going to create HelloWord Obj"); HelloWorld obj = (HelloWorld) context.getBean("hello"); obj.getMessage();// w w w. j av a 2 s.co m log.info("Exiting the program"); log.error(", "); // obj.printThrowException(); }
From source file:at.prasnikar.robert.springloaddataapp.loadDataApp.java
public static void main(String args[]) { ApplicationContext context = new ClassPathXmlApplicationContext( "classpath:META-INF/spring/applicationContext.xml"); manufacturerController manufacturerController = (manufacturerController) context.getBean("controller"); manufacturer mf = new manufacturer(); mf.setManufacturerName("AA"); mf.setId(1L);/*w ww. j a v a 2 s .co m*/ manufacturerController.getManufacturerService().createManufacturer(mf); System.out .println(manufacturerController.getManufacturerService().getManufacturer(1L).getManufacturerName()); mf.setManufacturerName("ABC"); mf.setId(2L); manufacturerController.add(mf); manufacturerController.print(); }
From source file:it.tai.solr.SolrMain.java
public static void main(String[] args) { log.info("--- STARTING Solr Probes ---"); ApplicationContext applicationContext = new ClassPathXmlApplicationContext("application-bean.xml"); }
From source file:it.pcan.test.integration.amqp.MainClient.java
/** * @param args the command line arguments * @throws java.lang.Exception//from w ww .j a v a2 s . c om */ public static void main(String[] args) throws Exception { try (ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( "classpath:/config/clientApplicationContext.xml")) { ClientGateway gateway = context.getBean(ClientGateway.class); TestBean result = gateway.process(new TestBean(2)); System.out.println("Result 1: " + result); try { result = gateway.process(new TestBean(-1)); System.out.println("Result 2: " + result); } catch (Exception ex) { System.out.println("Exception received " + ex); } gateway.process2(new DummyBean()); System.out.println("Done."); } }
From source file:pkg.MainApp.java
public static void main(String[] args) { // create application context and load beans configuration file AbstractApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml"); // get required bean. // getBean() uses bean ID to return a generic object // which finally can be casted to actual object HelloWorld obj = (HelloWorld) context.getBean("helloWorld"); obj.getMessage();//from w ww . ja v a 2s. c o m // use the singleton scope for stateless beans HelloWorld ojbSingleton1 = (HelloWorld) context.getBean("helloSingleton"); ojbSingleton1.setMessage("I'm Singleton"); ojbSingleton1.getMessage(); // output: Your Message : I'm Singleton HelloWorld ojbSingleton2 = (HelloWorld) context.getBean("helloSingleton"); ojbSingleton2.getMessage(); // output: Your Message : I'm Singleton // use the prototype scope for all state-full beans HelloWorld objPrototype1 = (HelloWorld) context.getBean("helloWorld"); objPrototype1.setMessage("I'm Prototype"); objPrototype1.getMessage(); // output: Your Message : I'm Prototype HelloWorld objPrototype2 = (HelloWorld) context.getBean("helloWorld"); objPrototype2.getMessage(); // output: null // register a shutdown hook method to ensure a graceful shutdown // and calls the relevant destroy methods context.registerShutdownHook(); // execute order: // postProcessBeforeInitialization // init // postProcessAfterInitialization // bean.getMessage // destroy }
From source file:MainClass.MyMain.java
public static void main(String[] args) { // BeanFactory fact = new XmlBeanFactory(new FileSystemResource("src/SpringConfig.xml")); AbstractApplicationContext con = new ClassPathXmlApplicationContext("SpringConfig.xml"); MyReinder rend = (MyReinder) con.getBean("firstrendrer"); rend.render();/*from w w w . j ava 2s. co m*/ MyReinder rendTwo = (MyReinder) con.getBean("secondrendrer"); rendTwo.render(); con.registerShutdownHook(); }
From source file:com.example.spring.app.ORMMain.java
public static void main(String[] args) { //Create Spring application context ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("spring/application-context.xml"); //Get service from context. (service's dependency (ProductDAO) is autowired in ProductService) ProductService productService = ctx.getBean(ProductService.class); //Do some data operation productService.add(new Product(1, "Bulb")); productService.add(new Product(2, "Dijone mustard")); System.out.println("listAll: " + productService.listAll()); //Test transaction rollback (duplicated key) try {/* w w w . j a v a2 s . c o m*/ productService.addAll( Arrays.asList(new Product(3, "Book"), new Product(4, "Soap"), new Product(1, "Computer"))); } catch (DataAccessException dataAccessException) { } //Test element list after rollback System.out.println("listAll: " + productService.listAll().size()); ctx.close(); }
From source file:com.home.ln_spring.ch5.event.Publisher.java
public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("classpath:events/events.xml"); Publisher p = (Publisher) context.getBean("publisher"); p.publish("Hello World!!!"); p.publish("The quik brown fox jumperd over the lazy dog"); }