父类序列化不了可以改成组合的方式,把原来的父类当成一个成员,代码如下:
class SOAPAScalaLogger() extends Serializable {
@transient
var logger: SOAPALogger = null
var moduleName: String = null
def setModuleName(name: String): Unit = {
moduleName = name
}
private def writeObject(out: ObjectOutputStream): Unit = {
out.defaultWriteObject()
out.writeObject(SOAPALogger.getAppID())
}
private def readObject(in: ObjectInputStream): Unit = {
in.defaultReadObject()
val appID = in.readObject().asInstanceOf[String]
SOAPALogger.setAppID(appID)
logger = SOAPALogManager.getLogger(moduleName, new SOAPACategoryFactory).asInstanceOf[SOAPALogger];
}
}