无法将JMX与Spring应用程序集成 [英] Cannot integrate JMX with Spring application

查看:84
本文介绍了无法将JMX与Spring应用程序集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 SPRING 应用程序。我跑的时候

I have got a SPRING application. When I run

mvn jetty:run

一切都好。

我想在我的项目中使用 JMX

I would like to use JMX in my project.

我创建了另一个项目,我为初学者尝试了教程,我能够看到 jconsole 的一些变化。

I created another project, I tried tutorial for beginners and I was able to see some changes with jconsole.

现在,我想在我的真实项目中使用JMX,我想使用管理JMX的SPRING库 - 按照这篇文章

Now, I want to use JMX in my real project and I would like to use SPRING libraries which manages JMX - following this post

< a href =https://stackoverflow.com/q/17010651/1021970>如何将JMX与Spring集成?

我上课了:

public class MyMainClass {
  private int var1;
  private int var2;
  private TimeUnit var3;

  // public getters and setters
  public static MyXXXClass<String, Object> getInstance();
}

config.xml

<!-- other beans -->
<bean id="myid" class="com.my.package.MyMainClass">
    <property name="var1" value.../>
    <property name="var2" value... />
    <property name="var3" value.../>
</bean>
<!-- other beans -->

我改变了一些东西,使其适用于JMX。

I changed few things to make it works with JMX.

我添加了一个界面:

import java.util.concurrent.TimeUnit;

public interface IMyMainClassBean {

    public int getVar1();

    public void setVar1(int var1);

    public int getVar2();

    public void setVar2(int var2);

    public TimeUnit getVar3();

    public void setVar3(TimeUnit var3);
}

我在课堂上添加了 implements

public class MyMainClassBean implements IMyMainClassBean {...}

最后,我编辑了我的xml文件:

Last thing, I edited my xml file:

<!-- other beans -->
<bean id="myid" class="com.my.package.MyMainClassBean">
    <property name="var1" value.../>
    <property name="var2" value... />
    <property name="var3" value.../>
</bean>

<!-- this bean must not be lazily initialized if the exporting is to happen -->
<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter"
    lazy-init="false">
    <property name="beans">
        <map>
            <entry key="bean:name=testBean1" value-ref="myid" />
        </map>
    </property>
</bean>
<!-- other beans -->

现在,当我启动服务器时,它给了我很多例外(日志真的很长,所以我只复制了一个我认为最重要的部分。

Now, when I start my server, it gives me a lot of exceptions (log is really long, so I copied just a part which I think is the most important).

Caused by: org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [com.my.package
.MyMainClassBean@3d4395fb] with key 'bean:name=testBean1'; nested exception is javax.management.InstanceAlreadyExistsExcep
tion: bean:name=testBean1
        at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:602)
        at org.springframework.jmx.export.MBeanExporter.registerBeans(MBeanExporter.java:527)
        at org.springframework.jmx.export.MBeanExporter.afterPropertiesSet(MBeanExporter.java:413)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableB
eanFactory.java:1571)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBean
Factory.java:1509)
        ... 163 more
Caused by: javax.management.InstanceAlreadyExistsException: bean:name=testBean1
        at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:453)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.internal_addObject(DefaultMBeanServerInterceptor.java:1484)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:963)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:917)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:312)
        at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:483)
        at org.springframework.jmx.support.MBeanRegistrationSupport.doRegister(MBeanRegistrationSupport.java:195)
        at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:655)
        at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:592)
        ... 167 more
[WARNING] Nested in org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'myTask' defined
 in class path resource [anotherconfigfile.xml]: Cannot resolve reference to bean 'anotherimport' while setting bean property 'targetObj
ect'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'anotherimport' defin
ed in class path resource [anotherconfigfile.xml]: Cannot create inner bean 'myTotallyAnotherClass' of type [com.my.package.another.MyTotallyAnotherClass]
 while setting bean property 'myTotallyAnotherClass'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creatin
g bean with name 'myTotallyAnotherClass' defined in class path resource [anotherconfigfile.xml]: Instantiation of bean failed; nested exception is
 org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [com.my.package.another.MyTotallyAnotherClass]: Co
nstructor threw exception; nested exception is java.lang.ExceptionInInitializerError:
javax.management.InstanceAlreadyExistsException: bean:name=testBean1
        at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:453)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.internal_addObject(DefaultMBeanServerInterceptor.java:1484)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:963)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:917)
        at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:312)
        at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:483)
        at org.springframework.jmx.support.MBeanRegistrationSupport.doRegister(MBeanRegistrationSupport.java:195)
        at org.springframework.jmx.export.MBeanExporter.registerBeanInstance(MBeanExporter.java:655)
        at org.springframework.jmx.export.MBeanExporter.registerBeanNameOrInstance(MBeanExporter.java:592)
        at org.springframework.jmx.export.MBeanExporter.registerBeans(MBeanExporter.java:527)
        at org.springframework.jmx.export.MBeanExporter.afterPropertiesSet(MBeanExporter.java:413)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableB
eanFactory.java:1571)

我甚至不知道如何调试它。

I have no even idea how to debug it.

感谢您的所有提示。

推荐答案


引起:javax.management.InstanceAlreadyExistsException:bean:name = testBean1

Caused by: javax.management.InstanceAlreadyExistsException: bean:name=testBean1

这是试图告诉你有两个豆子同名 ObjectName of bean:name = testBean1 正在注册 MBeanExporter 。但是,除非您的 beans 地图中有其他XML文件或更多条目,否则不应该有。

This is trying to tell you that you have 2 beans with the same name ObjectName of bean:name=testBean1 being register with the MBeanExporter. However, unless there are other XML files or more entries in your beans map then there should not be.


我甚至不知道如何调试它。

I have no even idea how to debug it.

你可以在<$ c $中放一个断点c> JmxMBeanServer.registerMBean(...)查看正在注册的bean的方法,看看你是否能找出你获得重复的原因。

You could put a breakpoint in the JmxMBeanServer.registerMBean(...) method to see what beans are being registered to see if you can figure out why you are getting a duplicate.

除此之外,我的 SimpleJMX库是通过JMX导出bean的简单方法。还有很好的Spring支持。以下是有关使用Spring 的文档。还有一个 Spring测试程序,演示了如何使其正常工作。这是 Spring XML文件

As an aside, my SimpleJMX library is an easy way to export your beans via JMX. There is pretty good Spring support as well. Here are the documentation about using with Spring. There is also a Spring test program which demonstrates what you need to do to get it working. Here's the Spring XML file.

这篇关于无法将JMX与Spring应用程序集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆