简体   繁体   中英

Catch external jar stop event for Spring-boot application with Intellij Idea

to launch my Spring Boot application in production environment my company has a system that executes "java -jar" and I'm trying to simultate it in my Intellij idea and jar starts correctly and I can debug with proyect source too.

In run and debug mode, when I click in stop button the jar is stopped suddenly with the message:

Disconnected from the target VM, address: '127.0.0.1:58575', transport: 'socket'

Process finished with exit code -1

And I can´t catch the close event to close my DB connections. I've tryed other stackoverflow solutions like PortalServiceLifeCycle , @PreDestroy and setRegisterShutdownHook(false) in SpringApplication run in main .

Jar is created by Maven with clean and package goals and we haven't xml spring configurations, only annotations.

What I need to catch shutdown service to close connections?

Edit: Add my Intellij buttons:

在此处输入图片说明

Thank you.

Please check this answer .

This feature is not available in Debug mode yet.

This feature is also not available for JAR run configuration, but is available for Application run configuration.

You can use remote debug and Ctrl+C in the external console to debug the code in the shutdown hooks until IDEA-171093 is implemented.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM