1 2 Previous Next 17 Replies Latest reply on Apr 18, 2012 4:39 AM by s.hostettler

    Producer Method and java.io.NotSerializableException

    s.hostettler

      Hello,

       

      There is something that I can really understand in my project. I get a java.io.NotSerializableException exception when Tomcat shuts down.

       

       

      {code}

      WARNING: Cannot serialize session attribute org.jboss.weld.context.ConversationContext.1#org.jboss.weld.bean-flat-ManagedBean-class ch.demo.web.ManageStudentRegistration for session 91DA3D803BD3BC86DCF7C5FF6BF6F942

      java.io.NotSerializableException: java.util.logging.Logger

                at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1164)

                at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1518)

                at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:{1483)

      {code}

       

      My managed bean has a logger field which is transient:

       

       

      {code}

      @Named

      @ConversationScoped

      public class ManageStudentRegistration implements Serializable {

       

      private static final long serialVersionUID = 2123342218792192804L;

      @Inject

      private transient Logger mLogger;

      ...

      {code}

       

       

      The producer for the logger looks like:

       

       

      {code}

      public class LoggerProducer  implements Serializable {

       

          private static final long serialVersionUID = -7352371086416154400L;

       

          @Produces

          public Logger getLogger(final InjectionPoint injectionPoint) {

              return LoggerFactory.getLogger(injectionPoint.getBean().getBeanClass());

          }

       

      }

      {code}

       

       

      I do not understand what field it tries to serializable as the mLogger is transient.

       

      In debug mode I get the following output from ObjectOutputStream.writeObject:

       

      {code}

      Bean: Producer Method [Logger] with qualifiers [@Any @Default] declared as [[method] @Produces public ch.demo.helpers.LoggerProducer.getLogger(InjectionPoint)]; Instance: org.slf4j.impl.JDK14LoggerAdapter(ch.demo.web.ManageStudentRegistration); CreationalContext: org.jboss.weld.context.CreationalContextImpl@17e34309

      {code}

       

      Obviously the problem is in the producer not in the member field mLogger.

       

      Did I miss something obvious?

       

      Many thanks in advance for your help

        1 2 Previous Next