存在安全原因,我無法將MBean添加到現有的JBoss 7平臺MBeanServer。所以我用customAuthenticator
創建了我自己的mBeanServer和JMXConnectorServer。額外的MBeanServer和JMXConnectorServer用於JBoss 7
這是我的新的MBeanServer和JMXConnectorServer的Spring Bean定義。當我在Jetty中運行我的應用程序時,此代碼有效。我可以通過jconsole中的URL服務:jmx:rmi:// localhost/jndi/rmi:// localhost:17999/sample進行連接,它只顯示我期望的自定義MBean。
但相同的代碼不會在JBoss中7。工作時,我部署到JBoss,並嘗試以相同的JMX URL連接,它給這個錯誤對話框:「來爲myuser @服務的連接:JMX:RMI: // localhost/jndi/rmi:// localhost:17999/trm沒有成功,您想再試一次嗎?「
我在我的customAuthenticator中放置了一個斷點,當我嘗試連接JMX時,JBoss不停止在我的中斷點。看來我的JMXConnectorServer沒有被JBoss使用。誰能幫忙?請注意,我無法更改現有的JBoss MBeanServer或JMX連接器服務器配置,因爲它們被用於其他目的。
在此先感謝。
@Bean
public Object rmiRegistry() throws Exception {
RmiRegistryFactoryBean factory = new RmiRegistryFactoryBean();
factory.setPort(17999);
factory.afterPropertiesSet();
return factory.getObject();
}
@Bean
@DependsOn("rmiRegistry")
public MBeanServer mBeanServer() {
MBeanServerFactoryBean factory = new MBeanServerFactoryBean();
factory.afterPropertiesSet();
return factory.getObject();
}
@Bean
@DependsOn("rmiRegistry")
public JMXConnectorServer jmxConnectorServer() throws IOException, JMException {
ConnectorServerFactoryBean factory = new ConnectorServerFactoryBean();
factory.setServer(mBeanServer());
factory.setServiceUrl("service:jmx:rmi://localhost/jndi/rmi://localhost:17999/sample");
factory.setRegistrationPolicy(RegistrationPolicy.FAIL_ON_EXISTING);
Map<String, Object> props = new HashMap<>();
props.put(JMXConnectorServer.AUTHENTICATOR, customAuthenticator);
factory.setEnvironmentMap(props);
factory.afterPropertiesSet();
return factory.getObject();
}
@Bean
@DependsOn("rmiRegistry")
public AnnotationMBeanExporter annotationMBeanExporter() {
AnnotationMBeanExporter result = null;
result = new AnnotationMBeanExporter();
result.setServer(mBeanServer());
return result;
}