gpt4 book ai didi

java - 配置并连接到 Spring JMX

转载 作者:行者123 更新时间:2023-12-01 15:18:36 24 4
gpt4 key购买 nike

我正在尝试为我的独立 Spring 应用程序配置 JMX 控制台。

我是这样配置的:

应用程序上下文:

<?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:aop="http://www.springframework.org/schema/aop" 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
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

<!-- Must for auto wiring
<context:annotation-config />
-->

<context:component-scan base-package="com.fixgw.beans">
</context:component-scan>


<bean id="FeedListenerBean" class="com.fixgw.beans.FeedListenerBean">
</bean>

<bean id="TriggerBean" class="com.fixgw.test.TriggerBean">
</bean>


<bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean" >
<property name="locateExistingServerIfPossible" value="true" />

</bean>


<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="bean:name=TriggerBean1" value-ref="TriggerBean" />
</map>
</property>
<property name="server" ref="mbeanServer" />
</bean>
</beans>

还有一个触发器 bean,我希望它的公共(public)方法在 JMX 中公开:

public class TriggerBean implements IJmxTriggerBean
{
static Logger logger = Logger.getLogger(TriggerBean.class);

FeedListenerBean fe = null;

public void start()
{
try
{
// init();
PropertyConfigurator.configure(FixGWConstants.LOG4J_PATH);
ApplicationContext context = new ClassPathXmlApplicationContext(FixGWConstants.APPLICATION_CONTEXT_XML);
fe = (FeedListenerBean) context.getBean("FeedListenerBean");
Thread t=new Thread()
{
public void run()
{
while (true)
{
System.out.println("a");
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};
t.run();
doTheListen();

}
catch (Throwable t)
{
logger.error(t);
System.out.println(t);
}

}

public void doTheListen()
{
fe.listen();
}

}


package com.finbird.fixgw.test;

public interface IJmxTriggerBean
{
public void doTheListen();
}
  1. 这足以进行配置吗?
  2. 现在我应该连接到哪个本地地址:端 Eloquent 能访问控制台?

谢谢,射线

最佳答案

您拥有 JMX 服务器,但需要一个 HTMLAdapter 才能通过浏览器查看这些 bean。例如来自this article :

  <bean id="htmlAdaptor" class="com.sun.jdmk.comm.HtmlAdaptorServer" init-method="start" />

<bean id="exporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="adaptor:name=htmlAdaptor" value-ref="htmlAdaptor" />
<entry key="bean:name=calculatorConfigBean" value-ref="calculatorConfig" />
</map>
</property>
<property name="server" ref="mbeanServer" />
</bean>

请注意,我假设此处具有 HTML/浏览器访问权限。请参阅here查看在代码中配置适配器的 Oracle 教程。

关于java - 配置并连接到 Spring JMX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11290719/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com