Example usage for org.springframework.context.support GenericXmlApplicationContext getBean

List of usage examples for org.springframework.context.support GenericXmlApplicationContext getBean

Introduction

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

Prototype

@Override
    public Object getBean(String name) throws BeansException 

Source Link

Usage

From source file:com.home.ln_spring.ch4.annotation.InjectSimple.java

public static void main(String args[]) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:app-context-annotation.xml");
    ctx.refresh();//from   ww w  .  jav  a  2  s  .c o m

    InjectSimple simple = (InjectSimple) ctx.getBean("injectSimple");
    System.out.println(simple);
}

From source file:com.home.ln_spring.ch4.xml.InjectSimple.java

public static void main(String args[]) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:app-context-xml.xml");
    ctx.refresh();/*from  w  w  w  .ja va2s  .  c  om*/

    InjectSimple simple = (InjectSimple) ctx.getBean("injectSimple");
    System.out.println(simple);
}

From source file:com.home.ln_spring.ch5.factory.AccessingFactoryBeans.java

public static void main(String[] args) {
    GenericXmlApplicationContext context = new GenericXmlApplicationContext();

    context.load("classpath:factory/factory.xml");
    context.refresh();/*w  w  w . j a v  a2  s  .c o m*/

    MessageDigest digest = (MessageDigest) context.getBean("shaDigest");

    MessageDigestFactoryBean factoryBean = (MessageDigestFactoryBean) context.getBean("&shaDigest");

    try {
        MessageDigest shaDigest = factoryBean.getObject();
        System.out.println(shaDigest.digest("HELLO WORLD!".getBytes()));
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.home.ln_spring.ch4.mi.MethodReplacementExample.java

public static void main(String args[]) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:replacement.xml");
    ctx.refresh();//  w ww.  j  a  va  2  s .  com

    ReplacementTarget replacementTarget = (ReplacementTarget) ctx.getBean("replacementTarget");
    ReplacementTarget standardTarget = (ReplacementTarget) ctx.getBean("standardTarget");

    displayInfo(replacementTarget);
    displayInfo(standardTarget);
}

From source file:com.mycompany.mavenproject3.xml.ConstructorConfusion.java

public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:META-INF/spring/app-context-xml.xml");
    ctx.refresh();/*from   w ww  .  j a v  a  2 s.  c o m*/
    ConstructorConfusion cc = (ConstructorConfusion) ctx.getBean("constructorConfusion");
    System.out.println(cc);
}

From source file:com.home.ln_spring.ch4.xml.InjectSimpleSpel.java

public static void main(String args[]) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:app-context-xml.xml");
    ctx.refresh();//  w  ww  .  j a v  a  2  s  .c  o  m
    InjectSimpleSpel spel = (InjectSimpleSpel) ctx.getBean("injectSimpleSpel");

    System.out.println(spel);
}

From source file:com.mycompany.mavenproject3.annotation.ConstructorConfusion.java

public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:META-INF/spring/app-context-annotation.xml");
    ctx.refresh();/* www  .  j av a 2 s . c o m*/
    ConstructorConfusion cc = (ConstructorConfusion) ctx.getBean("constructorConfusion");
    System.out.println(cc);
}

From source file:com.home.ln_spring.ch4.annotation.InjectSimpleSpel.java

public static void main(String args[]) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:app-context-annotation.xml");
    ctx.refresh();/*from ww w .  j a v a  2  s .co m*/

    InjectSimpleSpel spel = (InjectSimpleSpel) ctx.getBean("injectSimpleSpel");

    System.out.println(spel);
}

From source file:com.home.ln_spring.ch5.lifecycle.DestructiveBean.java

public static void main(String[] args) {
    GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
    ctx.load("classpath:lifecycle/disposeMethod.xml");
    ctx.refresh();/*from  w w  w . j  a v  a 2 s . com*/

    DestructiveBean bean = (DestructiveBean) ctx.getBean("destructiveBean");
    System.out.println("Calling destroy()");
    ctx.destroy();
    System.out.println("Called destroy()");
}

From source file:com.haythem.integration.Main.java

/**
 * Load the Spring Integration Application Context
 *
 * @param args - command line arguments//from   w w w .  ja v a  2s  .  c  om
 */
public static void main(final String... args) {

    final Scanner scanner = new Scanner(System.in);

    System.out.println("\n========================================================="
            + "\n                                                         "
            + "\n    Welcome to the Spring Integration                    "
            + "\n          TCP-Client-Server Sample!                      "
            + "\n                                                         "
            + "\n    For more information please visit:                   "
            + "\n    http://www.springintegration.org/                    "
            + "\n                                                         "
            + "\n=========================================================");

    final GenericXmlApplicationContext context = Main.setupContext();
    final SimpleGateway gateway = context.getBean(SimpleGateway.class);
    final AbstractServerConnectionFactory crLfServer = context.getBean(AbstractServerConnectionFactory.class);

    System.out.print("Waiting for server to accept connections...");
    TestingUtilities.waitListening(crLfServer, 10000L);
    System.out.println("running.\n\n");

    System.out.println("Please enter some text and press <enter>: ");
    System.out.println("\tNote:");
    System.out.println("\t- Entering FAIL will create an exception");
    System.out.println("\t- Entering q will quit the application");
    System.out.print("\n");
    System.out.println("\t--> Please also check out the other samples, " + "that are provided as JUnit tests.");
    System.out.println("\t--> You can also connect to the server on port '" + crLfServer.getPort()
            + "' using Telnet.\n\n");

    while (true) {

        final String input = scanner.nextLine();

        if ("q".equals(input.trim())) {
            break;
        } else {
            final String result = gateway.send(input);
            System.out.println(result);
        }
    }

    System.out.println("Exiting application...bye.");
    System.exit(0);

}