4 Replies Latest reply on Aug 22, 2011 3:30 PM by jimdwyer

    @Inject Logger does not work

    sg26565

      I am trying to get the LoggerProducer from the seam-solder package to work, but I always get the error message:

       

      WELD-001408 Unsatisfied dependencies for type [Logger] with qualifiers [@Default] at injection point [[field] @Inject private de.treichels.test.ejb.StartupSingleton.logger]
      

       

      My Java class looks like this:

       

      @Startup
      @Singleton
      public class StartupSingleton {
          @Inject
          private Logger logger;
      
      
          @Inject
          private Event<ContainerStartupEvent> event;
      
      
          @PostConstruct
          public void Start() {
              logger.info("fire startup event");
              event.fire(new ContainerStartupEvent());
          }
      }
      

       

      I was expecting that the Logger instance gets created by the org.jboss.seam.solder.logging.LoggerProducer class.

       

      class LoggerProducer {
         @Produces
         Logger produceLog(InjectionPoint injectionPoint) { ...}
      }
      

       

      I've added seam-solder-3.0.0.Final.jar as a dependency and it gets packaged into the resulting ear alongside with my ejb.jar. My application.xml looks like this:

       

      <?xml version="1.0" encoding="UTF-8"?>
      <application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" version="6">
        <display-name>myApp</display-name>
        <module>
          <ejb>myEjb-0.0.1-SNAPSHOT.jar</ejb>
        </module>
      </application>
      

       

      I seems that the LoggerProducer from the seam-solder-3.0.0.Final.jar is not recognized by the Weld runtime and therefore, no Logger get injected into my ejb.

       

      Can anyone help?

        • 1. Re: @Inject Logger does not work
          sg26565

          I found a solution.

           

          The seam-solder-3.0.0.Final.jar needs to be packaged into the lib subfolder of the ear. This is how my pom.xml for the ear looks like:

           

          <build>
               <plugins>
                    <plugin>
                         <groupId>org.apache.maven.plugins</groupId>
                         <artifactId>maven-ear-plugin</artifactId>
                         <version>2.4.2</version>
                         <configuration>
                              <version>6</version>
                              <defaultLibBundleDir>lib</defaultLibBundleDir>
                         </configuration>
                    </plugin>
                    ...
               </plugins>
          </build>
          

           

          Details can be found in https://docs.jboss.org/author/display/AS7/Class+Loading+in+AS7. I assume that adding a Class-Path: entry to MANIFEST.MF would also work, but I didn't test this.

           

          Here is another post on a related issue: http://community.jboss.org/thread/167102

          • 2. Re: @Inject Logger does not work
            jimdwyer

            Can you post you import statements.  I have a similar issue.  My code compiles but will not deploy.

             

            I get this error

             

            Caused by: java.lang.NoClassDefFoundError: Lorg/apache/log4j/Logger

             

            It seems that log4j is part of the server but I can't seem to get ahold of it.

             

            Here is my code:

             

             

            @Startup
            @Singleton
            @Remote(IngestRemote.class)
            @Local(IngestLocal.class)
            public class IngestMBean implements IngestRemote, IngestLocal{
             
            private static final Logger log = Logger.getLogger(IngestMBean.class);
            //@Inject private Logger log;


            @PostConstruct
            public void postConstruct() throws Exception{
                     log.info("postConstruct");
            }

            @PreDestroy
            public void preDestroy() throws Exception{
              log.info("preDestroy");
            }

            }

             

            I tried the @Inject and the old fashioned way with the same result.  What am I doing wrong.  I have no .xml files.  I let the bean autowire.

            • 3. Re: @Inject Logger does not work
              sg26565

              I'm using JBoss logging:

               

              import javax.annotation.PostConstruct;

              import javax.ejb.Singleton;

              import javax.ejb.Startup;

              import javax.inject.Inject;

              import org.jboss.logging.Logger

               

              Don't use org.apache.log4j.Logger directly. JBoss logging is a logging facade that abstracts the actual logging framework similar to commons logging or slf4j.

              • 4. Re: @Inject Logger does not work
                jimdwyer

                Thats it.  Thanks.