I have apache tomcat server which deploys war file and running the application. I have bean class which needs to execute bean life cycle method PreDestroy but it is not working. Also tried handling ContextStopped Event and ContextClosed event those are also not working. Added shutdown hook to JVM shutdown also that also did not worked.
I tried Overriding Pre-Destory method like just for printing log inside it.
@PreDestroy
public void cleanUp(){
logger.info("I am Destroyer of the world");
}
This log did not logged in the file when I stopped the apache tomcat server.
I have disabled the shutdownHook for logback configuration file so that it wont shutdown that will make sure even if IOC container shutdowns logback does not.
This also does not worked and folder also did not created.
Finally Tired, Something like
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
logger.info("Setter of application context");
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
logger.info("Destroyed");
try {
Files.createDirectories(Paths.get("C:\\DestroyWorld"));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
}
This also did not worked.
Note : My Bean is not of prototype Scope.