java.io.NotSerializableException: org.apache.log4j.Logger mistake says that lawsuit of org.apache.lo4j.Logger is non Serializable. This mistake comes when nosotros travel log4j for logging inward Java in addition to practise Logger inward a Serializable shape e.g. whatever domain shape or POJO which nosotros desire to shop inward HttpSession or desire to serialize it. As nosotros know from 10 Java Serialization interview question that, if yous accept a non serializable shape every bit fellow member inward a Serializable class, it volition throw java.io.NotSerializableException Exception.
Look at the below code :
public shape Customer implements Serializable{
private Logger logger = Logger.getLogger(Customer.class)
......
}
If lawsuit of Customer volition live stored inward HttpSession or Serialized externally it volition throw "java.io.NotSerializableException: org.apache.log4j.Logger" because hither logger lawsuit is neither static or transient in addition to it doesn't implement Serializable or Externalzable interface.
How to solve java.io.NotSerializableException: org.apache.log4j.Logger

public shape Customer implements Serializable{
private static lastly Logger logger = Logger.getLogger(Customer.class)
......
}
That's all on how to cook java.io.NotSerializableException: org.apache.log4j.Logger in Java. We accept seen what crusade java.io.NotSerializableException: org.apache.log4j.Logger, it's because Logger shape is non Serializable simply nosotros too learned that at that spot is no holler for serializing Logger lawsuit in addition to amend to brand Logger static in addition to final.
Further Learning
Complete Java Masterclass
2 ways to solve java.lang.OutOfMemoryError inward Java