1 Reply Latest reply on Jun 30, 2016 10:21 AM by Martin Kouba

    How do I invoke an injected method with Weld SE?

    Christian Wansart Newbie

      Hello,

       

      I'm trying to understand how to use method injection, but I cannot find a way to use it properly. I was wondering: Is it even possible with Weld SE or is this a feature that depends on a Java EE server?

       

      App.java

      public class App {
      
          public static void main(String[] args) {
              Weld weld = new Weld();
              WeldContainer container = weld.initialize();
              Foo foo = container.select(Foo.class).get();
              // call foo.test() here
          }
      }
      

       

      Foo.java

      public class Foo {
      
          @Inject
          public void test(Baz baz) {
              System.out.println("Baz: " + baz);
          }
      }
      

       

      Baz.java

      public class Baz {
      
          private String name = "Baz";
      
          @Override
          public String toString() {
              return "Baz{" + "name=" + name + '}';
          }
      }
      

       

      But how do I invoke foo.test() now with the injection? Is this possible?