예제 #1
0
 @Bean(destroyMethod = "byebye")
 // @Scope("prototype")
 public HelloWorld hw() {
   HelloWorld ret = new HelloWorld();
   ret.setMessage("hi");
   return ret;
 }
예제 #2
0
  public static void main(String[] args) {

    ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-config.xml");

    HelloWorld helloWorld = (HelloWorld) ctx.getBean("helloworld");

    helloWorld.Hello();
  }
예제 #3
0
 @Test
 public void test() {
   ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
   HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
   HelloWorld obj2 = (HelloWorld) context.getBean("helloWorld_2");
   obj.getMessage();
   obj2.getMessage();
 }
예제 #4
0
  public static void main(String[] args) {
    System.out.println("HI INSIDE aPP11");
    ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Module.xml");

    HelloWorld obj = (HelloWorld) context.getBean("helloBean");
    System.out.println("HI INSIDE aPP");
    obj.printHello();
  }
예제 #5
0
 public void testGetClassLoader() {
   HelloWorld hello = new HelloWorld();
   Class c = hello.getClass();
   ClassLoader loader = c.getClassLoader();
   System.out.println(loader);
   System.out.println(loader.getParent());
   System.out.println(loader.getParent().getParent());
 }
예제 #6
0
 public static void inheritanceExample() {
   System.out.println("----inheritanceExample----");
   AbstractApplicationContext ctx =
       new ClassPathXmlApplicationContext("com/wilson/testlab/spring/b/bean/beans.xml");
   HelloWorld helloWorldChild = (HelloWorld) ctx.getBean("helloWorldChild");
   helloWorldChild.getMessage();
   helloWorldChild.getMessage2();
   helloWorldChild.getMessage3();
 }
예제 #7
0
  public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");

    //        ApplicationContext context = newo GenericXmlApplicationContext("beans.xml");

    HelloWorld obj = (HelloWorld) context.getBean("helloWorld");

    obj.getMessage();
  }
예제 #8
0
  public static void main(String[] args) {
    @SuppressWarnings("resource")
    ApplicationContext context = new AnnotationConfigApplicationContext(HelloWorldConfig.class);

    HelloWorld obj = (HelloWorld) context.getBean(HelloWorld.class);

    obj.setMessage("Hello World!");
    obj.getMessage();
  }
예제 #9
0
  /**
   * @param args
   * @throws Exception
   */
  public static void main(final String[] args) throws Exception {

    final URL url = new URL("https://localhost:8443/HelloWorld/hello?wsdl");
    final QName qname = new QName("http://ws.mkyong.com/", "HelloWorldImplService");

    final Service service = Service.create(url, qname);
    final HelloWorld hello = service.getPort(HelloWorld.class);
    System.out.println(hello.getHelloWorldAsString());
  }
예제 #10
0
파일: MainApp.java 프로젝트: PhilTheAir/Jsp
  public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
    log.info("Going to create HelloWord Obj");

    HelloWorld obj = (HelloWorld) context.getBean("helloWorld");
    obj.getMessage();

    log.info("Exiting the program");
  }
예제 #11
0
  public static void beanPostProcessorExample() {

    System.out.println("----beanPostProcessorExample----");
    AbstractApplicationContext ctx =
        new ClassPathXmlApplicationContext("com/wilson/testlab/spring/b/bean/beans2.xml");

    HelloWorld singletonObjA = (HelloWorld) ctx.getBean("helloWorldCallback");
    singletonObjA.getMessage();
    ((AbstractApplicationContext) ctx).registerShutdownHook();
  }
예제 #12
0
  public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");

    HelloWorld objA = (HelloWorld) context.getBean("helloWorld");

    objA.setMessage("I'm object A");
    objA.getMessage();

    HelloWorld objB = (HelloWorld) context.getBean("helloWorld");
    objB.getMessage();
  }
  public static void main(String... args) {

    HelloWorld helloWorld =
        new HelloWorld() {
          @Override
          public void printGreeting() {
            System.out.println("ANONYMOUS: Hello World!");
          }
        };
    helloWorld.printGreeting();
  }
예제 #14
0
 @Test
 public void testSayHello() {
   Injector inj =
       Guice.createInjector(
           new Module() {
             @Override
             public void configure(Binder binder) {
               binder.bind(HelloWorld.class).to(HelloWorldImpl.class);
             }
           });
   HelloWorld hw = inj.getInstance(HelloWorld.class);
   assertEquals(hw.sayHello(), "Hello, world!");
 }
예제 #15
0
  public static void main(String args[]) throws IOException {
    //    if( args.length < 2 ) {
    //      System.out.println( "HelloWord <file> \"sentence to tag\"" );
    //      return;
    //    }

    String str = "This is Yarko, the ruller of all bananas.";
    InputStream is = new FileInputStream("en-pos-maxent.bin");
    HelloWorld hw = new HelloWorld(is);
    is.close();

    hw.run(str);
  }
예제 #16
0
  public static void main(String args[]) {

    URL url;
    try {
      url = new URL("http://localhost:1502/pack1/greet");
      QName qname = new QName("http://pack1/", "HelloWorldImplService");
      Service service = Service.create(url, qname);
      HelloWorld world = service.getPort(HelloWorld.class);
      System.out.println(world.greetings("susritha"));
      System.out.println(world.add(1, 2));
    } catch (MalformedURLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  public static void main(String[] args) {
    ApplicationContext applicationContext =
        new ClassPathXmlApplicationContext("application-context.xml");
    Profile profile = (Profile) applicationContext.getBean("profile");

    System.out.println();
    profile.printName();
    profile.printAge();

    HelloWorld helloWorld = (HelloWorld) applicationContext.getBean("helloWorld");
    helloWorld.getMessage();

    ((AbstractApplicationContext) applicationContext).registerShutdownHook();
    ((AbstractApplicationContext) applicationContext).close();
  }
  /** 获得HelloWorld的代理对象。 */
  public static HelloWorld getProxy() {
    // 接口的实现类
    HelloWorld helloWorld = new HelloWorldImpl();
    // proxy的调用类
    InvocationHandler handler = new HelloWorldHandler(helloWorld);

    // 生成proxy
    HelloWorld proxy =
        (HelloWorld)
            Proxy.newProxyInstance(
                helloWorld.getClass().getClassLoader(),
                helloWorld.getClass().getInterfaces(),
                handler);

    return proxy;
  }
예제 #19
0
 @Test
 public void givenHelloWorldWhenSetInvalidNameThenThrowException() {
   try {
     helloWorld.setName(null);
     fail("Should not be allowed to set name to null");
   } catch (IllegalArgumentException e) {
     // Ok
   }
 }
예제 #20
0
  @Test
  public void testEndpoint() throws Exception {
    URL wsdl = new URL("http://localhost:8080/hello-world/TestService?wsdl");
    QName serviceNS = new QName("http://ws.gss.redhat.com/", "TestServiceService");
    QName portNS = new QName("http://ws.gss.redhat.com/", "TestServicePort");

    Service service = Service.create(wsdl, serviceNS);
    HelloWorld port = service.getPort(portNS, HelloWorld.class);

    List<String> argArray = Collections.singletonList("Kyle");
    List<String> returnedArray = port.sayHello(argArray);
    assertEquals("Return value not equal to request arg", argArray.size(), returnedArray.size());
    for (int i = 0; i < argArray.size(); i++) {
      assertEquals(
          "Return value not equal to request arg",
          "Hello, " + argArray.get(i),
          returnedArray.get(i));
    }
  }
예제 #21
0
  public static void main(String[] args) {
    ApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");

    HelloWorld obj = (HelloWorld) context.getBean("helloWorld");

    SanalWorld sanalWorld = (SanalWorld) context.getBean("sanalWorld");

    JavaCollection javaCollection = (JavaCollection) context.getBean("javaCollection");

    System.out.println(obj.getMessage());

    System.out.println(sanalWorld.getFeeling());

    System.out.println(javaCollection.getList());

    System.out.println(javaCollection.getSet());

    System.out.println(javaCollection.getAddMap());

    System.out.println(javaCollection.getProps());
  }
예제 #22
0
  /*
  * The Spring Framework supports following five scopes, three of which are available only if you use a web-aware ApplicationContext.
  *  > singleton	This scopes the bean definition to a single instance per Spring IoC container (default).
  *  > prototype	This scopes a single bean definition to have any number of object instances.
  *  > request	This scopes a bean definition to an HTTP request. Only valid in the context of a web-aware Spring ApplicationContext.
  *  > session	This scopes a bean definition to an HTTP session. Only valid in the context of a web-aware Spring ApplicationContext.
  *  > global-session	This scopes a bean definition to a global HTTP session. Only valid in the context of a web-aware Spring ApplicationContext.

  */
  public static void scopeExample() {
    System.out.println("----scopeExample----");
    ApplicationContext ctx =
        new ClassPathXmlApplicationContext("com/wilson/testlab/spring/b/bean/beans.xml");

    HelloWorld singletonObjA = (HelloWorld) ctx.getBean("helloWorld");
    singletonObjA.setMessage("I'm object A");
    singletonObjA.getMessage();

    HelloWorld singletonObjB = (HelloWorld) ctx.getBean("helloWorld");
    singletonObjB
        .getMessage(); // get same instance as object A because bean's scope is defined as singleton

    HelloWorld prototypeObjA = (HelloWorld) ctx.getBean("helloWorld2");
    prototypeObjA.setMessage("I'm object B");
    prototypeObjA.getMessage();

    HelloWorld prototypeObjB = (HelloWorld) ctx.getBean("helloWorld2");
    prototypeObjB
        .getMessage(); // get different instance as object A because bean's scope is defined as
                       // prototype
  }
  public void sayHello() {

    class EnglishGreeting implements HelloWorld {
      String name = "world";

      public void greet() {
        greetSomeone("world");
      }

      public void greetSomeone(String someone) {
        name = someone;
        System.out.println("Hello " + name);
      }
    }

    HelloWorld englishGreeting = new EnglishGreeting();

    HelloWorld frenchGreeting =
        new HelloWorld() {
          String name = "tout le monde";

          public void greet() {
            greetSomeone("tout le monde");
          }

          public void greetSomeone(String someone) {
            name = someone;
            System.out.println("Salut " + name);
          }
        };

    HelloWorld spanishGreeting =
        new HelloWorld() {
          String name = "mundo";

          public void greet() {
            greetSomeone("mundo");
          }

          public void greetSomeone(String someone) {
            name = someone;
            System.out.println("Hola, " + name);
          }
        };
    englishGreeting.greet();
    frenchGreeting.greetSomeone("Fred");
    spanishGreeting.greet();
  }
예제 #24
0
  @Test
  public void givenHelloWorldWhenSetPropertiesAndSayThenReturnCorrectResult() {
    {
      helloWorld.setPhrase("Hello");
      helloWorld.setName("World");
      String result = helloWorld.say();
      assertThat(result, equalTo("Hello World"));
    }

    {
      helloWorld.setPhrase("Hey");
      helloWorld.setName("Universe");
      String result = helloWorld.say();
      assertThat(result, equalTo("Hey Universe"));
    }
  }
예제 #25
0
 public static void main(String[] args) {
   HelloWorld app = new HelloWorld();
   app.sendMessage();
 }
예제 #26
0
 public void useHelloWorld() {
   hw.printHelloWorld();
 }
예제 #27
0
 @Test
 public void testHelloEmpty() {
   assertEquals(h.getName(), "");
   assertEquals(h.getMessage(), "Hello!");
 }
예제 #28
0
 @Test
 public void testHelloWorld() {
   h.setName("World");
   assertEquals(h.getName(), "World");
   assertEquals(h.getMessage(), "Hello World!");
 }
예제 #29
0
 public static void main(String[] args) {
   XmlBeanFactory factory = new XmlBeanFactory(new ClassPathResource("Beans.xml"));
   HelloWorld obj = (HelloWorld) factory.getBean("helloWorld");
   System.out.println("message:" + obj.getMessage());
 }
예제 #30
0
 public static void main(String args[]) {
   HelloWorld.ConvertString("Hello,This is a Test");
 }