Ideas: Use Java's @PostConstruct tag, @PreConstruct tag.
Principle: The method modified by @PostConstruct will run when the Tomcat server loads the servlet, that is, when the Tomcat server starts;
The method modified by @PreConstruct will run when the Tomcat server unloads the servlet, that is, when the Tomcat server stops.
Note: Stopping Tomcat in eclipse will not execute the method modified by @PreConstruct. You must manually shut down the Tomcat server in the bin folder in the Tomcat installation directory to execute the method modified by @PreConstruct.
Reference: https://blog.csdn.net/jimxiaoming/article/details/51556454
https://www.cnblogs.com/landiljy/p/5764515.html