This commit is contained in:
Andy Wilkinson 2022-05-26 16:54:31 +01:00
parent 26b89bfc80
commit 14af1bb2dc
1 changed files with 3 additions and 5 deletions

View File

@ -74,8 +74,7 @@ public class StopMojo extends AbstractMojo {
return; return;
} }
getLog().info("Stopping application..."); getLog().info("Stopping application...");
try (JMXConnector connector = SpringApplicationAdminClient try (JMXConnector connector = SpringApplicationAdminClient.connect(this.jmxPort)) {
.connect(this.jmxPort)) {
MBeanServerConnection connection = connector.getMBeanServerConnection(); MBeanServerConnection connection = connector.getMBeanServerConnection();
stop(connection); stop(connection);
} }
@ -85,14 +84,13 @@ public class StopMojo extends AbstractMojo {
} }
} }
private void stop(MBeanServerConnection connection) throws IOException, MojoExecutionException { private void stop(MBeanServerConnection connection) throws IOException, MojoExecutionException {
try { try {
new SpringApplicationAdminClient(connection, this.jmxName).stop(); new SpringApplicationAdminClient(connection, this.jmxName).stop();
} }
catch (InstanceNotFoundException ex) { catch (InstanceNotFoundException ex) {
throw new MojoExecutionException( throw new MojoExecutionException(
"Spring application lifecycle JMX bean not found. Could not stop application gracefully", "Spring application lifecycle JMX bean not found. Could not stop application gracefully", ex);
ex);
} }
} }