java 警告:注册 Oracle JDBC Diagnosability MBean 时出错

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5191054/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 09:53:11  来源:igfitidea点击:

WARNING: Error while registering Oracle JDBC Diagnosability MBean

javajdbcoracle11g

提问by totolearning

We are getting the following error when using Oracle 11g ojdbc6.jar:

使用 Oracle 11g ojdbc6.jar 时出现以下错误:

WARNING: Error while registering Oracle JDBC Diagnosability MBean.
java.lang.NoSuchMethodError:
javax.management.StandardMBean.<init>(Ljava/lang/Class;Z)V
        at oracle.jdbc.driver.OracleDiagnosabilityMBean.<init>(OracleDiagnosabilityMBean.java:34)
        at oracle.jdbc.driver.OracleDriver.registerMBeans(OracleDriver.java:342)
        at oracle.jdbc.driver.OracleDriver.run(OracleDriver.java:199)

After investigating from many forums and blogs, we have not found any final solutions yet. So, we want to share the workaround way here.

经过多方论坛和博客的调查,我们还没有找到任何最终的解决方案。所以,我们想在这里分享解决方法。

回答by totolearning

According Oracle document, The JDBC diagnosability management feature introduces an MBean, oracle.jdbc.driver.OracleDiagnosabilityMBean. This MBean provides means to enable and disable JDBC logging, you can find it here: https://docs.oracle.com/cd/B28359_01/java.111/b31224/diagnose.htm.

根据 Oracle 文档,JDBC 诊断能力管理特性引入了一个 MBean,oracle.jdbc.driver.OracleDiagnosabilityMBean。此 MBean 提供启用和禁用 JDBC 日志记录的方法,您可以在此处找到它:https: //docs.oracle.com/cd/B28359_01/java.111/b31224/diagnose.htm

And, the driver uses java.util.logging for logging purpose, actually in our cases we don't really need to use that info, so decide to disable the log and there is NO warning happen anymore.

而且,驱动程序使用 java.util.logging 进行日志记录,实际上在我们的情况下,我们并不真正需要使用该信息,因此决定禁用日志并且不再发生警告。

How to disable the log for the driver (oracle.jdbc):

如何禁用驱动程序的日志(oracle.jdbc):

  • As default, JRE use the default properties file in JRE_HOME\lib\logging.properties, so edit the file and adding this info:
    • oracle.jdbc.level=OFF
  • Or configuring your own properties log file for java.util.logging
    • java -Djava.util.logging.config.file=/YourConfig.properties
    • Add oracle.jdbc.level=OFF to YourConfig.properties
  • 默认情况下,JRE 使用 JRE_HOME\lib\logging.properties 中的默认属性文件,因此编辑该文件并添加以下信息:
    • oracle.jdbc.level=OFF
  • 或者为 java.util.logging 配置您自己的属性日志文件
    • java -Djava.util.logging.config.file=/YourConfig.properties
    • 将 oracle.jdbc.level=OFF 添加到 YourConfig.properties

It works for us, don't get any WANRING error above.

它对我们有用,上面没有任何 WANRING 错误。

回答by codeDr

I had the exact same issue. I don't know if my environment is the same.

我有完全相同的问题。不知道我的环境是不是一样。

In my environment, I'm using both jdbc and jboss jars in the same application. I believe, but did not verify, that something in the jboss jars is hooking into the class loader and causing the issue.

在我的环境中,我在同一个应用程序中同时使用 jdbc 和 jboss jar。我相信,但没有验证,jboss jars 中的某些东西正在挂接到类加载器并导致问题。

I got around the issue by only loading the ojdbc driver jar, creating my database instance, and then loading the jboss jars.

我通过只加载 ojdbc 驱动程序 jar,创建我的数据库实例,然后加载 jboss jar 来解决这个问题。

回答by LeOn - Han Li

I'm using Maven and my project was using log4j 1.2.15. For whatever reason, 1.2.15has dependencies on jms 1.1, jmxtools 1.2.1, and jmxri 1.2.1.

我正在使用 Maven,我的项目正在使用log4j 1.2.15. 无论出于何种原因,1.2.15有依赖性jms 1.1jmxtools 1.2.1jmxri 1.2.1

jmxri 1.2.1contains a version of StandardMBeanwith a constructor that takes a StandardMBean(not java.lang.Class). While I did not do extensive testing to confirm this hypothesis, I believe that this is the version of the class that was being used, and the ultimate cause of the error.

jmxri 1.2.1包含一个StandardMBeanwith 构造函数的版本,该构造函数采用StandardMBean(not java.lang.Class)。虽然我没有进行大量测试来证实这个假设,但我相信这是正在使用的类的版本,也是导致错误的最终原因。

It seems as though log4j 1.2.14doesn't have those dependencies. So I backed down to 1.2.14, and took them out.

似乎log4j 1.2.14没有这些依赖项。所以我退缩到1.2.14,把它们拿出来。