@PostConstruct @PreDestroy

Viewed 3414

In jdk9 @PostConstruct and @PreDestroy are in java.xml.ws.annotation which is deprecated and scheduled for removal.

I was wondering what to use when they are removed and also wouldn't be a problem due to the fact that a lot of frameworks and projects are using them?

1 Answers

I have found answer on this link

This example is just first example which should prepare your code for the latest modifications:

@Component
public class MyBean implements InitializingBean, DisposableBean {

    private void init() {
        //TODO: init code
    }


    private void shutdown() {
        //TODO: destroy code
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        init();
    }

    @Override
    public void destroy() throws Exception {
        shutdown();
    }
}
Related