Does Spring make sure Closeable beans are closed in the correct order?

Viewed 9620

Let's pretend that we have two Closeable beans:

@Component
public class CloseableBean1 implements Closeable {

    private BufferedOutputStream outputStream;

    @Override
    public void close() throws IOException {
        try {
            outputStream.close();
        } catch (Exception e) {
            // ignore e
        }
    }
}


@Component
public class CloseableBean2 implements Closeable {    

    @Autowired
    private CloseableBean1 bean1;


    @Override
    public void close() throws IOException {
        try {
            bean1.close();
        } catch (Exception e) {
            // ignore e
        }
    }
}

Does Spring make sure that CloseableBean2 is closed first and then CloseableBean1 is closed?

1 Answers
Related