常用的XMBean创建方式:
1. 创建接口
package com.sim.ifc; public interface SimulatorMBean { public String test(); }
2. 创建实现bean
package com.sim.config; import org.jboss.ejb3.annotation.Service; import com.sim.ifc.SimulatorMBean; @Service(xmbean="resource:META-INF/simulator-xmbean.xml") public class SimulatorMBeanImpl implements SimulatorMBean { public String test() { return "Hello"; } }3. 在META-INF目录下创建simulator-xmbean.xml
完了以后打包丢进JBOSS就行了。在jboss.j2ee下可以找到<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE mbean PUBLIC "-//JBoss//DTD JBOSS XMBEAN 1.0//EN" "http://www.jboss.org/j2ee/dtd/jboss_xmbean_1_0.dtd"> <mbean> <description>The EJBBaseTest configuration management XMBean</description> <class>com.sim.config.SimulatorMBeanImpl</class> <constructor> <description>The default constructor</description> <name>SimulatorMBeanImpl</name> </constructor>
<!-- Operations --> <operation> <description>test</description> <name>test</name> <return-type>java.lang.String</return-type> </operation> </mbean>
点进去就能发现test方法
然而在Jboss AS 6上面,必须要在接口和类中显式的实现 create(), destroy(), start(), stop()方法,Jboss才能把它认作Management。
或者加上@management注解。
JBOSS下标准MBEAN创建方式:
<?xml version="1.0" encoding="UTF-8"?> <server xmlns="urn:jboss:service:7.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:jboss:service:7.0 jboss-service_7_0.xsd"> <mbean code="com.xx.XXX" name="com.xx:service=XXX"> </mbean> </server>