通过powermockrunner类运行时连接到自定义db驱动程序时出错

6tdlim6h  于 2021-06-30  发布在  Java
关注(0)|答案(2)|浏览(411)

当我尝试连接到数据库时,我的junit类出现以下错误,我正在使用powermockrunner进行junit。我尝试连接的驱动程序不是一个众所周知的或开源的,它是我公司定制的驱动程序。是引起问题的那个吗?这些痕迹是:

WARNING: Error while registering Oracle JDBC Diagnosability MBean.
java.lang.LinkageError: loading constraint violation: loader "org/powermock/core/classloader/javassist/JavassistMockClassLoader@591550a" previously initiated loading for a different type with name "javax/management/MBeanServer" defined by loader "com/ibm/oti/vm/BootstrapClassLoader@7ecd7c73"
    at java.lang.ClassLoader.defineClassImpl(Native Method)
    at java.lang.ClassLoader.defineClassInternal(ClassLoader.java:397)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:358)
    at org.powermock.core.classloader.javassist.JavassistMockClassLoader.loadUnmockedClass(JavassistMockClassLoader.java:90)
    at org.powermock.core.classloader.MockClassLoader.loadClassByThisClassLoader(MockClassLoader.java:104)
    at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass1(DeferSupportingClassLoader.java:147)
    at org.powermock.core.classloader.DeferSupportingClassLoader.loadClass(DeferSupportingClassLoader.java:98)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:880)
    at oracle.jdbc.driver.OracleDriver.registerMBeans(OracleDriver.java:409)
    at oracle.jdbc.driver.OracleDriver$1.run(OracleDriver.java:241)
    at java.security.AccessController.doPrivileged(AccessController.java:678)
    at oracle.jdbc.driver.OracleDriver.<clinit>(OracleDriver.java:237)
    at java.lang.Class.forNameImpl(Native Method)
3ks5zfa0

3ks5zfa01#

尝试在类声明上方添加以下注解以及其他注解

@PowerMockIgnore({"javax.management.*"})
zfycwa2u

zfycwa2u2#

你有 @PrepareForTest 在你的测试中?
如果是,那么当您连接时,它引用stub类并抛出expection。
添加 @PowerMockIgnore 要忽略的注解

@RunWith (PowerMockRunner.class)
...
@PowerMockIgnore({"java.sql.*", "javax.management.*", "org.apache.http.conn.ssl.*", "com.amazonaws.*", "javax.net.ssl.*","com.sun.*"})
public class ... {}

相关问题