Java 如何从本地连接从JNDI查找DomainRuntimeServiceBean? 我已经广泛搜索了Weblogic文档:

Java 如何从本地连接从JNDI查找DomainRuntimeServiceBean? 我已经广泛搜索了Weblogic文档:,java,weblogic,jndi,Java,Weblogic,Jndi,到目前为止,Oracle站点上的所有文档和我找到的所有示例都只显示了如何通过远程连接或本地MBeanServer实例获取对此MBean的引用 提到本地连接的一点是模糊和不完整的: MBean服务器的绝对JNDI名称。JNDI名称必须以开头 /jndi/,后跟表中所述的一个jndi名称 4-1 表4-1显示: MBean Server JNDI Name Domain Runtime MBean Server weblogic.management.mbean

到目前为止,Oracle站点上的所有文档和我找到的所有示例都只显示了如何通过远程连接或本地
MBeanServer
实例获取对此MBean的引用

提到本地连接的一点是模糊和不完整的:

MBean服务器的绝对JNDI名称。JNDI名称必须以开头
/jndi/
,后跟表中所述的一个jndi名称 4-1

表4-1显示:

MBean Server                  JNDI Name
Domain Runtime MBean Server   weblogic.management.mbeanservers.domainruntime
这不起作用,我尝试转储JNDI树,但在其中找不到任何相关内容

我在
AdminServer
上,所以这不是问题所在

我能找到的操作说明是获取对
MBServer
实例的引用,但这不是我需要的;示例:
(MBeanServer)ctx.lookup(“java:comp/env/jmx/domainRuntime”)

但这对我没有任何好处,它是
MBeanServer
的一个实例,我不想用
ObjectName
的东西来挖掘所有间接过程

我需要参考的是DomainRuntimeServiceBean接口: 我需要的是能够获得一个
domainRuntimeServiceBean
-

简短回答的实例 类型安全接口都已弃用,您必须手动执行查找/树遍历

从9.0开始,MBeanHome接口和 WebLogic服务器MBean已弃用。相反,JMX应用程序 与WebLogic服务器交互MBean应使用标准JMX设计 客户端使用 javax.management.MBeanServerConnection接口来发现MBean, 属性,以及运行时的属性类型

长话短说 在构造函数中:

ctx = new InitialContext();
this.domain = (MBeanServer) ctx.lookup("java:comp/env/jmx/domainRuntime");
this.domainObjectName = new ObjectName("com.bea:Name=DomainRuntimeService,Type=weblogic.management.mbeanservers.domainruntime.DomainRuntimeServiceMBean");
在您的方法中:

final ObjectName dr = (ObjectName) this.domain.getAttribute(domainObjectName, "DomainRuntime");
final ObjectName dm = (ObjectName) this.domain.getAttribute(dr, "DeploymentManager");
final ObjectName[] adrs = (ObjectName[]) this.domain.getAttribute(dm, "AppDeploymentRuntimes");
for (final ObjectName on : adrs)
{
    if (this.domain.getAttribute(on, "ApplicationName").equals(appName))
    {
        this.domain.invoke(on, "stop", null, null);
        break;
    }
}
当然,现在我必须编写自己的方便类,这些类是类型安全的,可以包装所有这些冗长的无意义的内容!
final ObjectName dr = (ObjectName) this.domain.getAttribute(domainObjectName, "DomainRuntime");
final ObjectName dm = (ObjectName) this.domain.getAttribute(dr, "DeploymentManager");
final ObjectName[] adrs = (ObjectName[]) this.domain.getAttribute(dm, "AppDeploymentRuntimes");
for (final ObjectName on : adrs)
{
    if (this.domain.getAttribute(on, "ApplicationName").equals(appName))
    {
        this.domain.invoke(on, "stop", null, null);
        break;
    }
}