How can I debug dropclizard with closed eclipse closing?

I am experimenting with Dropwizard ( https://github.com/robertkuhar/dropwiz_get_start , https://github.com/robertkuhar/dropwiz_mongo_demo ) and am impressed with how easy it is to integrate with my IDE. To run my dropwizard application, I just find the class with the main method and "Debug As ... Java Application", and I'm on my way. Stopping the application is equally simple, just click the red "Finish" button from the "Debug" view. However, I noticed that I don't get to breakpoints in the stop () method of my managed classes when I stop it this way.

How do I get Dropwizard to complete a graceful shutdown when launched directly in the eclipse debugger?

@Override
public void run( BlogConfiguration configuration, Environment environment ) throws Exception {
    ...
    MongoManaged mongoManaged = new MongoManaged( mongo );
    environment.manage( mongoManaged );
    ...
}

Breakpoints in stop () MongoManage never hit.

public class MongoManaged implements Managed {
    private final MongoClient mongo;

    public MongoManaged( MongoClient mongo ) {
        this.mongo = mongo;
    }

    @Override
    public void start() throws Exception {
    }

    @Override
    public void stop() throws Exception {
        if ( mongo != null ) {
            mongo.close();
        }
    }
}
+4
source share
1 answer

Does this java function help?

// In case vm shutdown
Runtime.getRuntime().addShutdownHook(new Thread() {
    @Override
    public void run()
    {
        // what should be closed if forced shudown
        // ....

        LOG.info(String.format("--- End of ShutDownHook (%s) ---", APPLICATION_NAME));
    }
});

Just add this before the first breakpoint.

0
source

Source: https://habr.com/ru/post/1533989/


All Articles