Example usage for org.springframework.context ApplicationContext getBean

List of usage examples for org.springframework.context ApplicationContext getBean

Introduction

In this page you can find the example usage for org.springframework.context ApplicationContext getBean.

Prototype

<T> T getBean(String name, Class<T> requiredType) throws BeansException;

Source Link

Document

Return an instance, which may be shared or independent, of the specified bean.

Usage

From source file:siia.helloworld.gateway.HelloWorldExample.java

public static void main(String args[]) {
    String cfg = "siia/helloworld/gateway/context.xml";
    ApplicationContext context = new ClassPathXmlApplicationContext(cfg);
    HelloService helloService = context.getBean("helloGateway", HelloService.class);
    System.out.println(helloService.sayHello("World"));
}

From source file:springaop.AopMain.java

/**
 * @param args the command line arguments
 *//*from  w ww .j  a v a  2s  . c  om*/
public static void main(String[] args) {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("spring.xml");
    ShapeService shapeService = ctx.getBean("shapeService", ShapeService.class);
    shapeService.getCircle();

}

From source file:siia.helloworld.channel.HelloWorldExample.java

public static void main(String args[]) {
    String cfg = "siia/helloworld/channel/context.xml";
    ApplicationContext context = new ClassPathXmlApplicationContext(cfg);
    MessageChannel channel = context.getBean("names", MessageChannel.class);
    Message<String> message = MessageBuilder.withPayload("World").build();
    channel.send(message);/*w ww. j a  va  2  s . c o  m*/
}

From source file:com.home.ln_spring.ch2.HelloWorldSpringDI.java

public static void main(String args[]) {
    // ? ApplicationContext.
    ApplicationContext context = new ClassPathXmlApplicationContext("app-context.xml");

    MessageRenderer mr = context.getBean("renderer", MessageRenderer.class);
    mr.render();/* w w w. j a v a  2  s .c  o  m*/

}

From source file:com.apress.prospringintegration.corespring.iocbasics.BasicBeanLifecycle.java

public static void main(String[] args) {

    ApplicationContext app = new ClassPathXmlApplicationContext("ioc_basics.xml");
    LoggingColorRandomizer lc = app.getBean("loggingColors", LoggingColorRandomizer.class);
    lc.exceptColor(lc.randomColor());/*w w  w  .  j a v a2  s .c o  m*/
    ((ClassPathXmlApplicationContext) app).close();
}

From source file:com.mycompany.run.MainSpring.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("konfiguracja.xml");
    UsersRepository userRepository = context.getBean("repozytoriumUzytkownikow", UsersRepository.class);
    User tomasz = userRepository.createUser("Tomasz_Spring");
}

From source file:com.swcguild.consolecontactlist.controller.App.java

public static void main(String[] args) {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
    ContactController controller = ctx.getBean("contactController", ContactController.class);
    controller.run();//from  w  w  w .  j  ava  2s.c o  m

}

From source file:org.springforpro.chptr5.event.Publisher.java

public static void main(String[] args) {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:events/events.xml");
    Publisher pub = ctx.getBean("publisher", Publisher.class);
    pub.publish("Hello world! Amigo!");
    pub.publish("The fast quick brown fox jumped over the lazy dog!");
}

From source file:com.apress.prospringintegration.corespring.config.componentscan.javaconfig.MainJavaConfig.java

public static void main(String[] args) throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("ioc_java_config.xml");
    ColorRandomizer cr = context.getBean("theOnlyColorRandomizer", ColorRandomizer.class);
    System.out.println(cr.randomColor());

    for (int i = 0; i < 5; i++)
        System.out.println("randomcolor: " + context.getBean("randomColor", ColorEnum.class));
}

From source file:com.swcguild.dvdlibraryv3.App.java

public static void main(String[] args) throws ParseException, FileNotFoundException, IOException {
    ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");

    DVDLibraryController ct = ctx.getBean("dvdLibraryController", DVDLibraryController.class);
    //        DVDLibraryController start = new DVDLibraryController();
    //        start.run();
    ct.run();/*  w w w.ja  va 2  s.c o  m*/
}