Wednesday 15 September 2010

java - Spring Boot shutdown hook -



java - Spring Boot shutdown hook -

how can register/add custom shutdown routine shall fire when spring boot application shuts down?

scenario: deploy spring boot application jetty servlet container (i.e., no embedded jetty). application uses logback logging, , want alter logging levels during runtime using logback's mbean jmx configurator. its documentation states avoid memory leaks, on shutdown specific loggercontext shutdown method has called.

what ways hear on spring boot shutdown events?

i have tried:

public static void main(string[] args) throws exception { configurableapplicationcontext cac = springapplication.run(example.class, args); cac.addapplicationlistener(new applicationlistener<contextclosedevent>() { @override public void onapplicationevent(contextclosedevent event) { logger.info("do something"); } }); }

but registered listener not called when application shuts down.

your listener registered late (that line never reached until context has closed). should suffice create @bean.

java spring-boot

No comments:

Post a Comment