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

Object getBean(String name) throws BeansException;

Source Link

Document

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

Usage

From source file:com.github.lanimall.ehcache2.AppNativeEhcache.java

public static void main(String[] args) {
    ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);

    MyDataServiceTester tester = (MyDataServiceTester) context.getBean("DataServiceWithCacheAsideTester");
    tester.test();//from  w  w  w  . jav a 2s.  c o  m

    //shut down the Spring context.
    ((ConfigurableApplicationContext) context).close();
}

From source file:com.github.lanimall.ehcache2.AppNoCache.java

public static void main(String[] args) {
    ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);

    MyDataServiceTester tester = (MyDataServiceTester) context.getBean("DataServiceTester");
    tester.test();//  w  ww  .  ja v a 2s .  c  o m

    //shut down the Spring context.
    ((ConfigurableApplicationContext) context).close();
}

From source file:com.github.lanimall.ehcache2.AppSpringCacheable.java

public static void main(String[] args) {
    ApplicationContext context = new AnnotationConfigApplicationContext(AppConfig.class);

    MyDataServiceTester tester = (MyDataServiceTester) context.getBean("DataServiceWithSpringCache");
    tester.test();//  w  w w. j  a v  a  2  s  .  c  o m

    //shut down the Spring context.
    ((ConfigurableApplicationContext) context).close();
}

From source file:com.golenok.lab_1_b.presentation.Main.java

/**
 * @param args the command line arguments
 *//*from w  ww . j  a  va 2  s .  c  o m*/
public static void main(String[] args) {

    ApplicationContext context = new ClassPathXmlApplicationContext("application_context.xml");
    ApplicationService appServices = (ApplicationService) context.getBean("applicationServices");

    appServices.delEntitiesStartNameWithK();
    appServices.delEntitiesWhereIdNoFibo();
}

From source file:org.apache.cxf.transport.xmpp.pep.Client.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("client-pep-applicationContext.xml");
    HelloWorld client = (HelloWorld) context.getBean("helloClient");

    long startTime = System.currentTimeMillis();
    client.yell("One way message!!!");
    System.out.println("Elapsed time: " + (System.currentTimeMillis() - startTime));

    startTime = System.currentTimeMillis();
    client.yell("Second message!!");
    System.out.println("Elapsed time: " + (System.currentTimeMillis() - startTime));
}

From source file:streaming.Main2.java

public static void main(String[] args) {
    ApplicationContext context = new FileSystemXmlApplicationContext(
            "file:/C:\\Users\\admin\\Documents\\Streaming\\application-context.xml");
    context.getBean(JFramePrincipale.class).setVisible(true);

}

From source file:com.dbconnection.DataSourceConnection.java

public static void main(String[] args) throws Exception {

    ApplicationContext appContext = new ClassPathXmlApplicationContext("beans.xml");
    DataSource dataSource = (DataSource) appContext.getBean("dataSource");

    Connection connection = dataSource.getConnection();
    System.out.println("Database with data source connected!");
    String result = query(connection);
    System.out.println(result);// w ww  .jav a2 s. c  o  m

}

From source file:com.letv.demo.Example.java

public static void main(String[] args) {
    ApplicationContext ctx = SpringApplication.run(Example.class, args);

    //init the system status
    RedissonService dAtomicLong = ctx.getBean(RedissonService.class);
    dAtomicLong.init();/*w  w  w.  j a  va2 s  .c  om*/
    log.info("set the {} = {}", RedissonService.NAME_GIFT_COUNT, dAtomicLong.getGiftCount());

}

From source file:pkg.SetterbasedDIMain.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
    SetterbasedDIJavaCollection jc = (SetterbasedDIJavaCollection) context.getBean("javaCollection");

    jc.getAddressList();// w  ww.ja  v  a2s . c om
    jc.getAddressSet();
    jc.getAddressMap();
    jc.getAddressProp();

    /*
    List Elements :[INDIA, Pakistan, USA, USA]
    Set Elements :[INDIA, Pakistan, USA]
    ap Elements :{1=INDIA, 2=Pakistan, 3=USA, 4=USA}
    Property Elements :{two=Pakistan, one=INDIA, three=USA, four=USA}
    */
}

From source file:org.apache.cxf.transport.xmpp.pubsub.Client.java

public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("client-pubsub-applicationContext.xml");
    HelloWorld client = (HelloWorld) context.getBean("helloClient");

    long startTime = System.currentTimeMillis();
    client.yell("One way message!!!");
    System.out.println("Elapsed time: " + (System.currentTimeMillis() - startTime));

    startTime = System.currentTimeMillis();
    client.yell("Second message!!");
    System.out.println("Elapsed time: " + (System.currentTimeMillis() - startTime));
}