2 Replies Latest reply on Feb 15, 2013 5:22 AM by feder

    Injecting a Logger within a Java SE application results in a NullPointerException

    feder Newbie



      I'm working on a new open source Java SE library. Presumably I'm missing a step about injection of a Log4J instance, since I always receive a NullpointerException when I wish to log. E.g. invoking logger.warning("foo").


      It goes without saying, that I have added Weld SE to may Maven dependencies







      I also added the beans.xml to /src/main/resources/META-INF/


      I added the producer method.


      package com.melinxa.logic.factories;


      import javax.enterprise.inject.Produces;

      import javax.enterprise.inject.spi.InjectionPoint;

      import org.apache.log4j.Logger;


      public class LogFactory {



          public Logger createLogger(InjectionPoint injectionPoint) {

              return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());





      Finally, I wish to inject a Logger with each of my Java files. But it returns a NullPointerException.

      {code}@Inject Logger logger{code}



      What is it that I'm missing? Why is the logger variable not instantiated?


      Again, it all works fine with Java EE (e.g. JBOSS AS 7) but it fails with a simple Java SE application.


      thanks a lot for any hints.