一碟小菜,请各位大虾品尝!!!!

darlingboy_lee 2006-04-14 06:02:36
本人菜鸟一个,最近在看jmx. 在spring下应用jmx出现问题. 抄了一篇相关文章的代码结果在jconsole中没有出现MBean的类.

代码如下:
1.MBean:

public interface HelloMBean {
// operations

public void sayHello();
public int add(int x, int y);

// attributes

// a read-only attribute called Name of type String
public String getName();

// a read-write attribute called CacheSize of type int
public int getCacheSize();
public void setCacheSize(int size);
}


==========================================================================================

2.implementsMBean

public class Hello implements HelloMBean {
public void sayHello() {
System.out.println("hello, world");
}
public int add(int x, int y) {
return x + y;
}
public String getName() {
return this.name;
}
public int getCacheSize() {
return this.cacheSize;
}
public synchronized void setCacheSize(int size) {
this.cacheSize = size;
System.out.println("Cache size now " + this.cacheSize);
}
private final String name = "Reginald";
private int cacheSize = DEFAULT_CACHE_SIZE;
private static final int DEFAULT_CACHE_SIZE = 200;
}

==========================================================================================

3.Main

public class Main {
public static void main(String[] args) throws Exception {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
Hello mbean = (Hello)context.getBean("hello");
System.out.println("Waiting forever...");
Thread.sleep(Long.MAX_VALUE);
}
}
=========================================================================================

4.spring的配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="hello" class="test.Hello"> </bean>
<bean id="mBeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"> </bean>
<bean id="startServer" class="test.StartServer">
<property name="server">
<ref local="mBeanServer"/>
</property>
</bean>
<bean id="exportor" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="bean:name=hello" value-ref="hello"/>
</map>
</property>
<property name="server">
<ref local="mBeanServer"/>
</property>
</bean>
</beans>


===========================================================================

请教各位大虾了!!!
...全文
66 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,615

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧