0

Consider the following pojo.

public class UserJMXBean {

private static List<User> userList = new ArrayList<>();

public static void addUser(User user){
   userList.add(user);
}

public static List<User> getUserList() {
    return userList;
}

public static void setUserList(List<User> userList) {
    UserJMXBean.userList = userList;
}
}

I have mapped this class as follows :

<bean class="com.mincom.util.deployment.MineStarPropertyConfigurer"/>

<bean id="userJMXBean"
      class="minestar.platform.domain.user.UserJMXBean"/>

<bean class="org.springframework.jmx.export.MBeanExporter" lazy-init="false">
    <property name="beans">
        <map>
            <entry key="bean:name=UserJMXBean" value-ref="userJMXBean"/>
        </map>
    </property>

</bean>

While debugging the pojo class I am getting my values of userlist but not when looking through jconsole. Please suggest.

lifeat stake
  • 65
  • 1
  • 9
  • I don't see anything JMX related in that bean also i doubt static methods are available in the JMX console. – M. Deinum Oct 08 '14 at 08:48
  • @M.Deinum Spring has a MBeanExpoter through which you can convert pojo to JMX. Here is the link [link](http://noushinb.blogspot.in/2011/02/spring-3-jmx.html) – lifeat stake Oct 08 '14 at 08:51
  • Trust me I known Spring (having written 2 books about it). The default config for the `MBeanExporter` exposes attributes, however your bean doesn't have any attributes only static methods. Your methods should be non static to be exposed. – M. Deinum Oct 08 '14 at 08:57
  • @M.Deinum Ok. Sorry, I didn't knew that... So, if I keep my methods non static the userList value will be exposed. I would also like to add that this is a standalone JVM server. It does not run on any app server. Will this work too? – lifeat stake Oct 08 '14 at 09:03
  • Why would there be a difference... It is all inside a JVM... JMX is JMX. – M. Deinum Oct 08 '14 at 09:05
  • @M.Deinum is there any other workaround. For some reason I need it to be static. As my other client jvm does not work without making it static.. – lifeat stake Oct 08 '14 at 10:32
  • Not that I'm aware of JMX only supports attributes and operations on the object. Not static operations on the type. – M. Deinum Oct 08 '14 at 10:38
  • @M.Deinum Got it Denium. I changed it to non static somehow and got the answer. If you can write an answer then I can mark it as answered. – lifeat stake Oct 13 '14 at 08:06

0 Answers0