I've been going through a bunch of documentation and SO posts and I found this solution to work (Is it possible to enable remote jmx monitoring programmatically?)
I'm sure you can translate your XML config into a @Configuration class to modernize your app as well:
@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;
}
Now for the getJmxEnvironment() method, add the custom objects to this map (the environment with jmx.remote.rmi.client.socket.factory and jmx.remote.rmi.server.socket.factory to your implementations)
Finally it wouldn't hurt to check these docs for some extra configuration points: https://docs.oracle.com/en/java/javase/17/docs/api/java.management.rmi/javax/management/remote/rmi/package-summary.html