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:exercise2.BlogConsole.java

protected static BlogService createBlogService() {
    // Use ApplicationContext to enable container-managed
    // transactions.
    ApplicationContext context = new ClassPathXmlApplicationContext("exercise2/applicationContext.xml");
    return context.getBean("blogService", BlogService.class);
}

From source file:solution1.BlogConsole.java

protected static BlogService createBlogService() {
    // Use ApplicationContext to enable container-managed
    // transactions.
    ApplicationContext context = new ClassPathXmlApplicationContext("solution1/applicationContext.xml");
    return context.getBean("blogService", BlogService.class);
}

From source file:solution2.BlogConsole.java

protected static BlogService createBlogService() {
    // Use ApplicationContext to enable container-managed
    // transactions.
    ApplicationContext context = new ClassPathXmlApplicationContext("solution2/applicationContext.xml");
    return context.getBean("blogService", BlogService.class);
}

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

public static void demonstrateScopes(ApplicationContext ctx) {
    for (int i = 0; i < 5; i++) {
        System.out.println("randomeverytime: " + ctx.getBean("randomeverytime", ColorEnum.class));
        System.out.println("alwaysthesame: " + ctx.getBean("alwaysthesame", ColorEnum.class));
    }/*from   w  w  w  . j  ava2s .c  o  m*/
}