1

ローカルのTomcatサーバー上のEclipse内で単純なSpringJMXアプリケーションを試してみましたが、mbeanを登録できないため、Eclipseコンテキスト内でjconsole内で表示できるようになりました:component-scanは私が作成したBeanを取得するように見えますただし、これらは登録されていません。プログラムでmbeanを登録すると、機能します。

これが私のconfigxmlファイルです。

<?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">

<bean id="mbeanServer" class="java.lang.management.ManagementFactory"
lazy-init="false" factory-method="getPlatformMBeanServer">
</bean>

<context:component-scan base-package="com.jmx.beans" />
<context:mbean-export server="mbeanServer" />

</beans>

アノテーションで登録しようとしている単純なBean

package com.jmx.beans;

import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedResource;
import org.springframework.stereotype.Component;

@Component
@ManagedResource(objectName="bean:name=Hello")
public class Hello{

String message =  null;

@ManagedAttribute(description="get the message")
public String getMessage(){

    return this.message;
}

@ManagedAttribute(description="set the message")
public void setMessage(String Message){

    this.message = Message;

}
}

また、Tomcatサーバーの引数を次のように設定しました

-Dcom.sun.management.jmxremote 
-Dcom.sun.management.jmxremote.port=9990
-Dcom.sun.management.jmxremote.ssl=false 
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.hostname="localhost"

これに関する助けをいただければ幸いです、ありがとう

4

2 に答える 2

4

投稿を編集して削除したのはなぜ<context:component-scan/>ですか?それはあなたを見つけるために必要です@Component

私はテストしたばかりで、すべてうまくいきました...

@Component
@ManagedResource
public class Foo {

    @ManagedAttribute
    public int getIt() {
        return 42;
    }
}

<context:mbean-server/>

<context:component-scan base-package="foo" />

<context:mbean-export/>

私はあなたのスタイルのMBeanサーバーでそれを試しましたが、それもうまくいきました。

于 2013-03-14T15:50:57.907 に答える
1

古い質問ですが、まだ有効です。Mbeanが表示されない問題については、次のvm引数を使用できます。

-Dspring.jmx.enabled=true
于 2021-08-17T08:53:16.593 に答える