首页 > 解决方案 > 如果在 Weblogic 集群上注册,MBean 不显示

问题描述

情况是:

  1. 应用服务器:Weblogic 12.2.1.2
  2. 应用程序:企业应用程序

工作场景:

  1. 部署在管理服务器上的应用程序。
  2. JConsole 正确显示了我的 MXBean。

不工作的情况:

  1. 应用程序部署在 2 个托管服务器的集群上。
  2. 在每个受管服务器上配置 JMX。
  3. JConsole 不显示我的 MXBean。

下面是我的源代码相关片段。

public class JpaCacheDescriptor {
    private String name;
    private int    size;

    @ConstructorProperties({ "name", "size" })
    public JpaCacheDescriptor(String name, int size) {
        this.name = name;
        this.size = size;
    }

    // Not relevant
}

public interface JpaCacheManager {
    List<JpaCacheDescriptor> getCaches();
    void clearAll();
}

@Slf4j
public class JpaCacheManagerImpl
    extends    StandardMBean
    implements JpaCacheManager
{
    private static ObjectName objectName;

    private static MBeanServer getMBeanServer()
        throws NamingException
    {
        InitialContext initialContext = new InitialContext();

        return (MBeanServer)initialContext.lookup("java:comp/jmx/runtime");
    }

    public JpaCacheManagerImpl()
        throws NotCompliantMBeanException
    {
        super(JpaCacheManager.class);
    }

    public static void register() {
        log.info("{ }");

        try {
            objectName = new ObjectName(String.format(
                "${wls.jmx.root}:name=${application.name},version=${application.version},node=%s,type=%s",
                System.getProperty("weblogic.Name"),
                JpaCacheManager.class.getSimpleName()
            ));

            JpaCacheManagerImpl jpaCacheMBean = new JpaCacheManagerImpl();
            StandardMBean       standardMBean = new StandardMBean(jpaCacheMBean, JpaCacheManager.class, true); // Force MXBean which is not inferred by @MXBean and MXBean prefix!!!

            getMBeanServer().registerMBean(standardMBean, objectName);

            log.info("Registered as \"{}\".", objectName.getCanonicalName());
        } catch (
              InstanceAlreadyExistsException
            | MalformedObjectNameException
            | MBeanRegistrationException
            | NamingException
            | NotCompliantMBeanException exception
        ) {
            objectName = null;
            log.error(exception.getMessage(), exception);
        }
    }

    public static void unregister() {
        log.info("{ }");

        if (null == objectName) {
            log.warn("MBean not registered!");
        } else {
            try {
                getMBeanServer().unregisterMBean(objectName);

                log.info("MBean unregistered.");
            }
            catch (
                  InstanceNotFoundException
                | MBeanRegistrationException
                | NamingException exception
            ) {
                log.error(exception.getMessage(), exception);
            }
        }
    }

    @Override
    public List<JpaCacheDescriptor> getCaches() {
        // Not relevant
    }

    @Override
    public void clearAll() {
        // Not relevant
    }
}

我花了很多时间寻找解决方案,但没有运气!

先感谢您。

标签: weblogicjmxjconsolemxbean

解决方案


我直接从 Oracle ( https://blogs.oracle.com/weblogicserver/managing-weblogic-servers-with-jconsole ) 获得了解决方案。

请看以下注意事项:

jconsole -J-Djava.class.path=$JAVA_HOME/lib/jconsole.jar:$JAVA_HOME/lib/tools.jar:$WL_HOME/server/lib/wljmxclient.jar \
         -J-Djmx.remote.protocol.provider.pkgs=weblogic.management.remote \
         -debug

Remote URL:
  - Managed Server Runtime : service:jmx:iiop://<MANAGED_HOST>:<PORT>/jndi/weblogic.management.mbeanservers.runtime
  - Domain Runtime         : service:jmx:iiop://<ADMIN_HOST>:<PORT>/jndi/weblogic.management.mbeanservers.domainruntime

User: <USER_NAME>
Password: <PASSWORD>

推荐阅读