Currently the only feature boot offers to do this is in the SpringApplication.getExitCode method which is private and only used by the SpringApplication.exit(..) which closes the context.
While the user can home roll their own getExitCode() method to capture the data prior to the context getting closed, it would be useful to add a ExitCodeGenerators class that supports this feature.