我正在使用Spring集成,但希望使用jmxtrans来监视我的拆分器。与下面的简单示例一样,我尝试计算到达拆分器的请求数。
@ManagedResource
public class Splitter {
private final AtomicInteger count = new AtomicInteger();
@ManagedAttribute
public int getCount(){
return this.count.get();
}
public List<JsonNode> split(Message<ArrayNode> message) {
count.incrementAndGet();
...
}
}
// spring integration workflow
<int:gateway id="myGateway" service-interface="someGateway" default-request-channel="splitChannel" error-channel="errorChannel" default-reply-channel="replyChannel" async-executor="MyThreadPoolTaskExecutor"/>
<int:splitter id="mySplitter" input-channel="splitChannel" output-channel="transformChannel" method="split">
<bean class="Splitter" />
</int:splitter>
// in MBeanExporter, I added
<entry key="myApplication:type=Splitter,name=splitter" value-ref="mySplitter" />
// query
<query
objectName='myApplication:type=Splitter,name=splitter'
attribute='Count'
resultAlias='myApplication.Splitter.count'/>
<collectIntervalInSeconds>20</collectIntervalInSeconds>我不能查询数据,得到这个错误。
javax.management.AttributeNotFoundException: getAttribute failed: ModelMBeanAttributeInfo not found for number
at javax.management.modelmbean.RequiredModelMBean.getAttribute(RequiredModelMBean.java:1524)
at org.springframework.jmx.export.SpringModelMBean.getAttribute(SpringModelMBean.java:109)发布于 2016-10-11 12:54:35
噢!很抱歉错过了。现在我看到你的代码:
<int:splitter id="mySplitter" input-channel="splitChannel" output-channel="transformChannel" method="split">
<bean class="Splitter" />
</int:splitter>因此,<bean class="Splitter" />是内部bean,在任何其他环境中都是不可见的。
要使它正常工作,您应该将bean定义移到顶层,并从<splitter>中引用它
<bean id="mySplitter" class="Splitter" />
<int:splitter id="mySplitter" input-channel="splitChannel" output-channel="transformChannel" ref="mySplitter" method="split"/>您使用<splitter>组件进行JMX导出,它实际上不公开内部bean,只公开它自己的托管属性/操作。
https://stackoverflow.com/questions/39964163
复制相似问题