Question

I am referring here

http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/jmx.html#jmx-proxy

I am trying to connect to localhost MBeanServer and perform some operation using Spring Proxy. The problem is just specifying the ObjectName and ProxyInterface, I am unable to connect to localhost. I am able to solve this problem by specifying the server property of the MBeanProxyFactoryBean.

Here is my spring context.xml

bean id="proxyWithoutServer" class="org.springframework.jmx.access.MBeanProxyFactoryBean"
          p:objectName="com.xxx.yyy"
          p:proxyInterface="com.MyInterface" 

bean id="proxyWithServer" class="org.springframework.jmx.access.MBeanProxyFactoryBean"
          p:objectName="com.xxx.yyy"
          p:proxyInterface="com.MyInterface" 
p:server-ref="clientConnector"

<bean id="clientConnector" class="org.springframework.jmx.support.MBeanServerConnectionFactoryBean"
          p:serviceUrl="service:jmx:rmi://localhost/jndi/rmi://localhost:8001/jmxrmi" />

In Java code, I simply do

MyInterface myInterface = context.getBean("proxyWithoutServer");
myInterface.myMethod();

But this doesnt work. - Says Unable to connect to localhost

But If I use

MyInterface myInterface = context.getBean("proxyWithServer");
myInterface.myMethod();

This works.

The problem here is that this code would be run on multiple servers and the jmx port in each would be different. SO I would not want to specify the port number. Hence I would like the proxyWithoutServer version of this to work. Looking at the spring jmx documentation it seems we do not need to specify the server port if we are trying to connect to local MBean Server. Would need some advice on what I am doing wrong here.

Thanks in advance

Was it helpful?

Solution

Create a local reference to the MBeanServer.

<context:mbean-server id="localMBeanServer"/>

Then use localMBeanServer in the p:server-ref.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top