Based on Is it possible to enable remote jmx monitoring programmatically?
I was able to give an answer to this: https://stackoverflow.com/a/79126986/17205238
TLDR; Register a Bean and manually startup the JMX rmi connector pass environment variables as needed (https://docs.oracle.com/javase/8/docs/technotes/guides/jmx/tutorial/security.html in my example via the method getJmxEnvironment())
@Bean
Registry rmiRegistry() throws Exception {
var jmxPort = getJmxPort(); //get your port from a property? jmx.port
var registry = LocateRegistry.createRegistry(jmxPort);
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi://0.0.0.0:"+jmxPort+"/jndi/rmi://127.0.0.1:"+jmxPort+"/jmxrmi");
JMXConnectorServer srvr = JMXConnectorServerFactory.newJMXConnectorServer(url, getJmxEnvironment(), mbs);
srvr.start();
return registry;
}
Hope it helps