spring-projects/spring-boot · error · MojoExecutionException

Could not invoke shutdown operation

Error message

Could not invoke shutdown operation

What it means

MBeanException during stop() means the 'shutdown' MBean operation itself threw an application-level exception (a clean throw from the bean, distinct from ReflectionException which wraps JVM-level reflective failures). Wrapped as MojoExecutionException preserving the original MBeanException as cause.

Solutions

  1. Inspect the wrapped MBeanException for the underlying cause
  2. Review application shutdown logic (SmartLifecycle, @PreDestroy)
  3. Ensure no custom Lifecycle blocks ApplicationContext.close()
Defensive patterns

Strategy: try-catch

Try / catch

try { client.stop(); } catch (MojoExecutionException ex) { log.error("Application threw during shutdown: {}", ex.getCause()); /* decide: force kill or report */ }

Prevention

When it happens

Trigger: The shutdown operation on the lifecycle MBean threw an application exception (e.g. LifecycleProcessor failed, a SmartLifecycle bean errored on stop).

Common situations: Custom SmartLifecycle beans blocking or failing during close; @PreDestroy methods throwing; shutdown hook contention.

Related errors


AI-assisted analysis of spring-projects/spring-boot@270dfe353f (2026-08-11). Data as JSON: /api/errors/e5443ccf25ed89fd. Report an issue: GitHub.

Appendix: source

Thrown at build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/SpringApplicationAdminClient.java:93

			throw new MojoExecutionException(ex.getMessage(), ex);
		}
	}

	/**
	 * Stop the application managed by this instance.
	 * @throws MojoExecutionException if the JMX service could not be contacted
	 * @throws IOException if an I/O error occurs
	 * @throws InstanceNotFoundException if the lifecycle mbean cannot be found
	 */
	void stop() throws MojoExecutionException, IOException, InstanceNotFoundException {
		try {
			this.connection.invoke(this.objectName, "shutdown", null, null);
		}
		catch (ReflectionException ex) {
			throw new MojoExecutionException("Shutdown failed", ex.getCause());
		}
		catch (MBeanException ex) {
			throw new MojoExecutionException("Could not invoke shutdown operation", ex);
		}
	}

	private ObjectName toObjectName(String name) {
		try {
			return new ObjectName(name);
		}
		catch (MalformedObjectNameException ex) {
			throw new IllegalArgumentException("Invalid jmx name '" + name + "'");
		}
	}

	/**
	 * Create a connector for an {@link javax.management.MBeanServer} exposed on the
	 * current machine and the current port. Security should be disabled.
	 * @param port the port on which the mbean server is exposed
	 * @return a connection
	 * @throws IOException if the connection to that server failed

View on GitHub (pinned to 270dfe353f)