문제

I am using Apache Wicket with Apache Commons Net. But when I define

new FTPClient(); //apache commons net library

I get an exception

org.apache.commons.net.ftp.FTPClient at.erpel.as2connector.testtool.protocols.FTP.client
[class=org.apache.commons.net.ftp.FTPClient] <----- field that is not serializable

What can I do?

도움이 되었습니까?

해결책 2

Thank you for your suggestions!

I also have solved it with 2 possibilites:

1) you can make the field transient:

transient FTPClient() client;

2) Make a Singleton of parent class where FTPClient will be used

public class AnyClass implements Serializable {

    private static AnyClass instance;

    private AnyClass() {

    }

    public static AnyClass getInstance() {
        if (instance == null) {
            instance = new AnyClass();
        }
        return instance;
    }

    FTPClient client = new FTPClient();
    ...
}

3) As suggested by biziclop: Create an own Class only for FTP Communication.

다른 팁

I don't think storing an FTPClient instance over multiple requests is a good idea to start with. You should create your FTPClient, use it and then discard it straight away. That would mean you can store it in local variables and don't have to worry about it not being serializable. (Which, by the way, makes sense, as it has a complex state, including active TCP connections.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top