Connecting to JMX server in spring throws exception!
Try to add the following system properties to disable security:
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.port=39600
![Rihards](https://i.stack.imgur.com/L2uIx.jpg?s=256&g=1)
Rihards
Updated on June 05, 2022Comments
-
Rihards about 2 years
So when I try to connect to jmx from jconsole I get this exception:
Caused by: java.rmi.ConnectException: Connection refused to host: 78.84.17.116; nested exception is: java.net.ConnectException: Connection timed out: connect at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601) at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198) ...
I was trying to connect to such url in jconsole:
service:jmx:rmi:///jndi/rmi://78.84.17.116:43030/test
My jmx spring configuration:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:mbean-server /> <bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter"> <property name="server" ref="jmxServer" /> <property name="assembler"> <bean class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler"> <property name="attributeSource"> <bean class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource" /> </property> </bean> </property> <property name="beans"> <map> <entry key="SpringBeans:name=hibernateStatisticsMBean" value-ref="hibernateStatisticsMBean" /> </map> </property> </bean> <bean id="jmxServer" class="org.springframework.jmx.support.MBeanServerFactoryBean" p:locateExistingServerIfPossible="false" /> <bean id="serverConnector" class="org.springframework.jmx.support.ConnectorServerFactoryBean" depends-on="rmiRegistry" p:objectName="connector:name=rmi" p:serviceUrl="service:jmx:rmi://78.84.17.116/jndi/rmi://localhost:43030/test" /> <bean name="hibernateStatisticsMBean" class="org.hibernate.jmx.StatisticsService"> <property name="statisticsEnabled" value="true" /> <property name="sessionFactory" ref="sessionFactory" /> </bean> <bean id="rmiRegistry" class="org.springframework.remoting.rmi.RmiRegistryFactoryBean"> <property name="port" value="43030" /> </bean> </beans>
What could I be doing wrong that jconsole doesn't want to connect to this jmx server? And what does
test
in the end of jmx url mean? I just saw that it like that in a tutorial so I wrote the same in my url.Edit 1: When I run
netstat -ntlp
on server I get this: tcp6 0 0 :::10099 :::* LISTEN 10754/javaWhere 10754 is the right java application. Is that correct? Running telnet ..*.* on 10099 I get a message that it connected to it too. So I guess it's not firewall on server side?
Edit 2: Okay well I'm trying now (and the exception bellow was thrown on server too) to run the app on my local environment (in Eclipse) and I guessing that it ain't server problem because all the same things happen.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverConnector' defined in class path resource [META-INF/hw-common-jmx.xml]: Invocation of init method failed; nested exception is java.io.IOException: Cannot bind to URL [rmi://localhost:43030/test]: javax.naming.NoPermissionException [Root exception is java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.AccessException: Cannot modify this registry] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1420) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563) at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) at star.Server.main(Server.java:31) Caused by: java.io.IOException: Cannot bind to URL [rmi://localhost:43030/test]: javax.naming.NoPermissionException [Root exception is java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.AccessException: Cannot modify this registry] at javax.management.remote.rmi.RMIConnectorServer.newIOException(RMIConnectorServer.java:804) at javax.management.remote.rmi.RMIConnectorServer.start(RMIConnectorServer.java:417) at org.springframework.jmx.support.ConnectorServerFactoryBean.afterPropertiesSet(ConnectorServerFactoryBean.java:172) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) ... 12 more Caused by: javax.naming.NoPermissionException [Root exception is java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.AccessException: Cannot modify this registry] at com.sun.jndi.rmi.registry.RegistryContext.bind(RegistryContext.java:126) at com.sun.jndi.toolkit.url.GenericURLContext.bind(GenericURLContext.java:208) at javax.naming.InitialContext.bind(InitialContext.java:400) at javax.management.remote.rmi.RMIConnectorServer.bind(RMIConnectorServer.java:625) at javax.management.remote.rmi.RMIConnectorServer.start(RMIConnectorServer.java:412) ... 15 more Caused by: java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.AccessException: Cannot modify this registry at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:396) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250) at sun.rmi.transport.Transport$1.run(Transport.java:159) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:155) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255) at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233) at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359) at sun.rmi.registry.RegistryImpl_Stub.bind(Unknown Source) at com.sun.jndi.rmi.registry.RegistryContext.bind(RegistryContext.java:120) ... 19 more Caused by: java.rmi.AccessException: Cannot modify this registry at sun.management.jmxremote.SingleEntryRegistry.bind(SingleEntryRegistry.java:61) at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source) at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:386) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250) at sun.rmi.transport.Transport$1.run(Transport.java:159) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:155) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662)
Could the problem be in configuration? Could someone verify that my configuration is correct?
Edit 3: I get this each time when I start the app. I guess that is the problem. It happens both on server and my machine..
01:40:21.588 [main] INFO org.springframework.remoting.rmi.RmiRegistryFactoryBean - Looking for RMI registry at port '38457' 01:40:21.654 [main] DEBUG org.springframework.remoting.rmi.RmiRegistryFactoryBean - RMI registry access threw exception java.rmi.ConnectException: Connection refused to host: 188.40.111.83; nested exception is: java.net.ConnectException: Connection refused at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:601) ~[na:1.6.0_12] at sun.rmi.transport.tcp.TCPChannel.createConnection(TCPChannel.java:198) ~[na:1.6.0_12] at sun.rmi.transport.tcp.TCPChannel.newConnection(TCPChannel.java:184) ~[na:1.6.0_12] at sun.rmi.server.UnicastRef.newCall(UnicastRef.java:322) ~[na:1.6.0_12] at sun.rmi.registry.RegistryImpl_Stub.list(Unknown Source) ~[na:1.6.0_12] at org.springframework.remoting.rmi.RmiRegistryFactoryBean.testRegistry(RmiRegistryFactoryBean.java:281) [org.springframework.context-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.remoting.rmi.RmiRegistryFactoryBean.getRegistry(RmiRegistryFactoryBean.java:259) [org.springframework.context-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.remoting.rmi.RmiRegistryFactoryBean.getRegistry(RmiRegistryFactoryBean.java:236) [org.springframework.context-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.remoting.rmi.RmiRegistryFactoryBean.getRegistry(RmiRegistryFactoryBean.java:193) [org.springframework.context-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.remoting.rmi.RmiRegistryFactoryBean.afterPropertiesSet(RmiRegistryFactoryBean.java:164) [org.springframework.context-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1477) [org.springframework.beans-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1417) [org.springframework.beans-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) [org.springframework.beans-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456) [org.springframework.beans-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:291) [org.springframework.beans-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) [org.springframework.beans-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:288) [org.springframework.beans-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) [org.springframework.beans-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:281) [org.springframework.beans-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190) [org.springframework.beans-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:563) [org.springframework.beans-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:895) [org.springframework.context-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:425) [org.springframework.context-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139) [org.springframework.context-3.0.5.RELEASE.jar:3.0.5.RELEASE] at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83) [org.springframework.context-3.0.5.RELEASE.jar:3.0.5.RELEASE] at star.Server.main(Server.java:31) [star-engine-13.05.11.jar:na] Caused by: java.net.ConnectException: Connection refused at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.6.0_12] at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) ~[na:1.6.0_12] at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195) ~[na:1.6.0_12] at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182) ~[na:1.6.0_12] at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366) ~[na:1.6.0_12] at java.net.Socket.connect(Socket.java:519) ~[na:1.6.0_12] at java.net.Socket.connect(Socket.java:469) ~[na:1.6.0_12] at java.net.Socket.<init>(Socket.java:366) ~[na:1.6.0_12] at java.net.Socket.<init>(Socket.java:180) ~[na:1.6.0_12] at sun.rmi.transport.proxy.RMIDirectSocketFactory.createSocket(RMIDirectSocketFactory.java:22) ~[na:1.6.0_12] at sun.rmi.transport.proxy.RMIMasterSocketFactory.createSocket(RMIMasterSocketFactory.java:128) ~[na:1.6.0_12] at sun.rmi.transport.tcp.TCPEndpoint.newSocket(TCPEndpoint.java:595) ~[na:1.6.0_12] ... 25 common frames omitted
-
Tarlog about 13 yearsYep. You should add them to command line (if your are running from a command line) or to some kind of JAVA_OPTS if you are running server
-
Rihards about 13 years@tarlog, so did as you said and I get this exception:
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'serverConnector' defined in class path resource [META-INF/hw-common-jmx.xml]: Invocation of init method failed; nested exception is java.io.IOException: Cannot bind to URL [rmi://localhost:39600/myconnector]: javax.naming.NoPermissionException [Root exception is java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: java.rmi.AccessException: Cannot modify this registry]
Need stack trace? -
Rihards about 13 yearsAny idea what does the access exceptions mean?
-
Tarlog about 13 yearsdo you run with SecurityManager?
-
Rihards about 13 years@Tarlog, added stack trace (and one question to main post) for the exception what is thrown when I run the app with system properties you provided. (I just changed the port to 43030 in -Dcom.sun.management.jmxremote.port)
-
Rihards about 13 years@Tarlog, by the way, when not running my app with these params so the exception is not thrown on my local machine I tried opening jconsole and select the app by process id and it worked out like a charm. However accessing it with the url didn't work..
-
Rihards about 13 years@Tarlog, can you check if my service url is correct? I really don't understand why there has to be localhost and my ip in it and a /test in the end. What should the remote url I enter in jconsole to connect look like?
-
Rihards about 13 years@Tarlog, I doubt I run with any securityManager. Haven't seen anything like that in my app.
-
Tarlog about 13 yearsSee if this thread helps: forum.springsource.org/archive/index.php/t-26140.html
-
joensson almost 10 yearsThat was not enough in my case (Spring 3.2.5). I had to stop using the RmiRegistryFactoryBean and use registry = LocateRegistry.createRegistry(jmxPort); before I was allowed to register anything.
-
joensson almost 10 yearsI had the com.sun.management.jmxremote properties mentioned set - but still got the AccessException - I then replaced my use of the RmiRegistryFactoryBean in Spring with a call to LocateRegistry.createRegistry(jmxPort) - and I could register my mbeans without getting exceptions. The problem only occurred for me when running my war inside an embedded Jetty (for integrationtest). When I deployed my war in other app servers I was allowed to register my mbeans. It seems like Jetty (9) auto creates a remote rmiregistry on the com.sun.management.jmxremote.port but with other security settings