1 Reply Latest reply on Feb 11, 2010 10:20 AM by niox.nikospara.yahoo.com

    question about static objects and injection

    norad2

      Can anyone explain why this doesn't work? Can static objects not be injected or is it the create true part that is making it not work?


      @Name("test")
      @Scope(ScopeType.APPLICATION)
      public class Test {
              @In(create=true)
              private static TestObject testObj;
              
              public static void doSomething() {
                      testObj.doSomethingElse(); // testObj is null at runtime
              }
      }
      

        • 1. Re: question about static objects and injection
          niox.nikospara.yahoo.com

          Using static fields is generally bad practice. I do not know if Seam supports injection into static member fields, but it may indeed not support it because it is bad practice.


          Do you really need static fields?


          Application scoped components are in effect singletons and may replace static fields in the majority of the cases.