Why am I getting the error "connection refused" with JMX

Caused by: java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested exception is:

Most likely you are not running your server with the right JVM parameters. Jconsole uses a different mechanism to find and to connect to local processes. Your client code is trying to use TCP/IP to connect to your server. To turn this on you'll need to add something like the following to your Java command line on your server:

-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=1099

See: How to activate JMX on my JVM for access with jconsole?

As an aside, you might want to consider using my SimpleJMX library which does all this code for you. It includes a JMX client code as well.


I received the same error. In my case I was using a @PostConstruct annotation and that method was attempting to use the RMI connection before Spring had a chance to configure the connection.

It didn't end up being anything wrong with the configuration of the connection, just that I accidentally tried to use it before it was ready. Hope this might help someone.


I've manage run Tomcat with JMX (Tomcat 8, Windows) by:

  1. add -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false

  2. run with admin permissions