1. <small id='c1Oak'></small><noframes id='c1Oak'>

    <tfoot id='c1Oak'></tfoot>
    <i id='c1Oak'><tr id='c1Oak'><dt id='c1Oak'><q id='c1Oak'><span id='c1Oak'><b id='c1Oak'><form id='c1Oak'><ins id='c1Oak'></ins><ul id='c1Oak'></ul><sub id='c1Oak'></sub></form><legend id='c1Oak'></legend><bdo id='c1Oak'><pre id='c1Oak'><center id='c1Oak'></center></pre></bdo></b><th id='c1Oak'></th></span></q></dt></tr></i><div id='c1Oak'><tfoot id='c1Oak'></tfoot><dl id='c1Oak'><fieldset id='c1Oak'></fieldset></dl></div>

      • <bdo id='c1Oak'></bdo><ul id='c1Oak'></ul>
    1. <legend id='c1Oak'><style id='c1Oak'><dir id='c1Oak'><q id='c1Oak'></q></dir></style></legend>

      Mockito、Java 9 和 java.lang.ClassNotFoundException:sun.ref

      时间:2023-09-26
      • <bdo id='4wDnn'></bdo><ul id='4wDnn'></ul>
      • <i id='4wDnn'><tr id='4wDnn'><dt id='4wDnn'><q id='4wDnn'><span id='4wDnn'><b id='4wDnn'><form id='4wDnn'><ins id='4wDnn'></ins><ul id='4wDnn'></ul><sub id='4wDnn'></sub></form><legend id='4wDnn'></legend><bdo id='4wDnn'><pre id='4wDnn'><center id='4wDnn'></center></pre></bdo></b><th id='4wDnn'></th></span></q></dt></tr></i><div id='4wDnn'><tfoot id='4wDnn'></tfoot><dl id='4wDnn'><fieldset id='4wDnn'></fieldset></dl></div>

            <tbody id='4wDnn'></tbody>

              <small id='4wDnn'></small><noframes id='4wDnn'>

              <legend id='4wDnn'><style id='4wDnn'><dir id='4wDnn'><q id='4wDnn'></q></dir></style></legend>

              • <tfoot id='4wDnn'></tfoot>

              • 本文介绍了Mockito、Java 9 和 java.lang.ClassNotFoundException:sun.reflect.ReflectionFactory的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我的项目是一个使用 Mockito 测试库的 Wildfly 13 应用程序.该应用程序未使用 Java 9 模块结构.只要服务器在 Java 8 上运行,测试就可以正常工作,但是一旦我们升级到 Java 9,它们就会失败,并出现以下异常:

                My project is a Wildfly 13 application which uses Mockito testing library. The app is not using Java 9 module structure. As long as the server ran on Java 8 the tests worked fine, but once we upgraded to Java 9 they failed with the following exception:

                org.objenesis.ObjenesisException: java.lang.ClassNotFoundException: sun.reflect.ReflectionFactory from [Module "test.war" from Service Module Loader]
                at test.war//org.objenesis.instantiator.sun.SunReflectionFactoryHelper.getReflectionFactoryClass(SunReflectionFactoryHelper.java:63)
                at test.war//org.objenesis.instantiator.sun.SunReflectionFactoryHelper.newConstructorForSerialization(SunReflectionFactoryHelper.java:37)
                at test.war//org.objenesis.instantiator.sun.SunReflectionFactoryInstantiator.<init>(SunReflectionFactoryInstantiator.java:41)
                at test.war//org.objenesis.strategy.StdInstantiatorStrategy.newInstantiatorOf(StdInstantiatorStrategy.java:68)
                at test.war//org.objenesis.ObjenesisBase.getInstantiatorOf(ObjenesisBase.java:94)
                at test.war//org.objenesis.ObjenesisBase.newInstance(ObjenesisBase.java:73)
                at test.war//org.mockito.internal.creation.instance.ObjenesisInstantiator.newInstance(ObjenesisInstantiator.java:19)
                at test.war//org.mockito.internal.creation.bytebuddy.SubclassByteBuddyMockMaker.createMock(SubclassByteBuddyMockMaker.java:47)
                at test.war//org.mockito.internal.creation.bytebuddy.ByteBuddyMockMaker.createMock(ByteBuddyMockMaker.java:25)
                at test.war//org.mockito.internal.util.MockUtil.createMock(MockUtil.java:35)
                at test.war//org.mockito.internal.MockitoCore.mock(MockitoCore.java:68)
                at test.war//org.mockito.Mockito.mock(Mockito.java:1895)
                at test.war//org.mockito.Mockito.mock(Mockito.java:1804)
                at test.war//application code...
                

                我尝试了各种选项和组合:

                I tried all kinds of options and combinations:

                • 使用 Java 8、9、10 编译
                • 使用最新版本的 OpenJDK 9 和 10 运行
                • 设置编译器和虚拟机选项 --add-modules jdk.unsupported 和 --add-exports jdk.unsupported/sun.reflect=ALL-UNNAMED"

                总是同样的错误.我没有想法.

                Always the same error. I'm out of ideas.

                --show-module-resolution的结果

                root jdk.javadoc jrt:/jdk.javadoc
                root jdk.jdi jrt:/jdk.jdi
                root jdk.jshell jrt:/jdk.jshell
                root jdk.sctp jrt:/jdk.sctp
                root jdk.xml.dom jrt:/jdk.xml.dom
                root jdk.jsobject jrt:/jdk.jsobject
                root jdk.unsupported jrt:/jdk.unsupported
                root jdk.scripting.nashorn jrt:/jdk.scripting.nashorn
                root jdk.httpserver jrt:/jdk.httpserver
                root jdk.management jrt:/jdk.management
                root jdk.net jrt:/jdk.net
                root jdk.security.auth jrt:/jdk.security.auth
                root jdk.dynalink jrt:/jdk.dynalink
                root java.se jrt:/java.se
                root jdk.compiler jrt:/jdk.compiler
                root jdk.accessibility jrt:/jdk.accessibility
                root jdk.jartool jrt:/jdk.jartool
                root jdk.jconsole jrt:/jdk.jconsole
                root jdk.attach jrt:/jdk.attach
                root jdk.security.jgss jrt:/jdk.security.jgss
                jdk.security.jgss requires java.logging jrt:/java.logging
                jdk.security.jgss requires java.security.sasl jrt:/java.security.sasl
                jdk.security.jgss requires java.security.jgss jrt:/java.security.jgss
                jdk.attach requires jdk.internal.jvmstat jrt:/jdk.internal.jvmstat
                jdk.jconsole requires jdk.attach jrt:/jdk.attach
                jdk.jconsole requires java.rmi jrt:/java.rmi
                jdk.jconsole requires jdk.management jrt:/jdk.management
                jdk.jconsole requires java.management jrt:/java.management
                jdk.jconsole requires jdk.management.agent jrt:/jdk.management.agent
                jdk.jconsole requires java.desktop jrt:/java.desktop
                jdk.jconsole requires jdk.internal.jvmstat jrt:/jdk.internal.jvmstat
                jdk.jconsole requires java.management.rmi jrt:/java.management.rmi
                jdk.accessibility requires java.desktop jrt:/java.desktop
                jdk.compiler requires java.compiler jrt:/java.compiler
                java.se requires java.datatransfer jrt:/java.datatransfer
                java.se requires java.compiler jrt:/java.compiler
                java.se requires java.scripting jrt:/java.scripting
                java.se requires java.desktop jrt:/java.desktop
                java.se requires java.security.sasl jrt:/java.security.sasl
                java.se requires java.naming jrt:/java.naming
                java.se requires java.sql.rowset jrt:/java.sql.rowset
                java.se requires java.security.jgss jrt:/java.security.jgss
                java.se requires java.sql jrt:/java.sql
                java.se requires java.management.rmi jrt:/java.management.rmi
                java.se requires java.management jrt:/java.management
                java.se requires java.xml.crypto jrt:/java.xml.crypto
                java.se requires java.instrument jrt:/java.instrument
                java.se requires java.rmi jrt:/java.rmi
                java.se requires java.prefs jrt:/java.prefs
                java.se requires java.logging jrt:/java.logging
                java.se requires java.xml jrt:/java.xml
                jdk.dynalink requires java.logging jrt:/java.logging
                jdk.security.auth requires java.naming jrt:/java.naming
                jdk.security.auth requires java.security.jgss jrt:/java.security.jgss
                jdk.management requires java.management jrt:/java.management
                jdk.scripting.nashorn requires java.logging jrt:/java.logging
                jdk.scripting.nashorn requires java.scripting jrt:/java.scripting
                jdk.scripting.nashorn requires jdk.dynalink jrt:/jdk.dynalink
                jdk.jsobject requires java.desktop jrt:/java.desktop
                jdk.xml.dom requires java.xml jrt:/java.xml
                jdk.jshell requires java.compiler jrt:/java.compiler
                jdk.jshell requires jdk.compiler jrt:/jdk.compiler
                jdk.jshell requires java.logging jrt:/java.logging
                jdk.jshell requires jdk.internal.opt jrt:/jdk.internal.opt
                jdk.jshell requires jdk.internal.le jrt:/jdk.internal.le
                jdk.jshell requires jdk.jdi jrt:/jdk.jdi
                jdk.jshell requires java.prefs jrt:/java.prefs
                jdk.jshell requires jdk.internal.ed jrt:/jdk.internal.ed
                jdk.jdi requires jdk.attach jrt:/jdk.attach
                jdk.jdi requires jdk.jdwp.agent jrt:/jdk.jdwp.agent
                jdk.javadoc requires java.xml jrt:/java.xml
                jdk.javadoc requires java.compiler jrt:/java.compiler
                jdk.javadoc requires jdk.compiler jrt:/jdk.compiler
                java.security.sasl requires java.logging jrt:/java.logging
                java.security.jgss requires java.naming jrt:/java.naming
                java.rmi requires java.logging jrt:/java.logging
                jdk.management.agent requires java.management jrt:/java.management
                jdk.management.agent requires java.management.rmi jrt:/java.management.rmi
                java.desktop requires java.xml jrt:/java.xml
                java.desktop requires java.prefs jrt:/java.prefs
                java.desktop requires java.datatransfer jrt:/java.datatransfer
                java.management.rmi requires java.naming jrt:/java.naming
                java.management.rmi requires java.management jrt:/java.management
                java.management.rmi requires java.rmi jrt:/java.rmi
                java.naming requires java.security.sasl jrt:/java.security.sasl
                java.sql.rowset requires java.logging jrt:/java.logging
                java.sql.rowset requires java.naming jrt:/java.naming
                java.sql.rowset requires java.sql jrt:/java.sql
                java.sql requires java.logging jrt:/java.logging
                java.sql requires java.xml jrt:/java.xml
                java.xml.crypto requires java.logging jrt:/java.logging
                java.xml.crypto requires java.xml jrt:/java.xml
                java.prefs requires java.xml jrt:/java.xml
                java.management binds java.management.rmi jrt:/java.management.rmi
                java.management binds jdk.management jrt:/jdk.management
                jdk.jshell binds jdk.editpad jrt:/jdk.editpad
                java.naming binds jdk.naming.dns jrt:/jdk.naming.dns
                java.naming binds jdk.naming.rmi jrt:/jdk.naming.rmi
                java.datatransfer binds java.desktop jrt:/java.desktop
                jdk.dynalink binds jdk.scripting.nashorn jrt:/jdk.scripting.nashorn
                java.base binds jdk.charsets jrt:/jdk.charsets
                java.base binds java.security.jgss jrt:/java.security.jgss
                java.base binds java.security.sasl jrt:/java.security.sasl
                java.base binds java.naming jrt:/java.naming
                java.base binds jdk.security.jgss jrt:/jdk.security.jgss
                java.base binds java.smartcardio jrt:/java.smartcardio
                java.base binds jdk.crypto.ec jrt:/jdk.crypto.ec
                java.base binds jdk.crypto.cryptoki jrt:/jdk.crypto.cryptoki
                java.base binds java.xml.crypto jrt:/java.xml.crypto
                java.base binds java.desktop jrt:/java.desktop
                java.base binds jdk.localedata jrt:/jdk.localedata
                java.base binds jdk.jlink jrt:/jdk.jlink
                java.base binds jdk.jdeps jrt:/jdk.jdeps
                java.base binds jdk.compiler jrt:/jdk.compiler
                java.base binds jdk.jartool jrt:/jdk.jartool
                java.base binds jdk.javadoc jrt:/jdk.javadoc
                java.base binds jdk.zipfs jrt:/jdk.zipfs
                java.base binds java.management jrt:/java.management
                java.base binds jdk.security.auth jrt:/jdk.security.auth
                java.base binds java.logging jrt:/java.logging
                java.compiler binds jdk.compiler jrt:/jdk.compiler
                java.compiler binds jdk.javadoc jrt:/jdk.javadoc
                jdk.internal.jvmstat binds jdk.jstatd jrt:/jdk.jstatd
                java.scripting binds jdk.scripting.nashorn jrt:/jdk.scripting.nashorn
                jdk.jstatd requires java.rmi jrt:/java.rmi
                jdk.jstatd requires jdk.internal.jvmstat jrt:/jdk.internal.jvmstat
                jdk.jdeps requires java.compiler jrt:/java.compiler
                jdk.jdeps requires jdk.compiler jrt:/jdk.compiler
                jdk.jlink requires jdk.jdeps jrt:/jdk.jdeps
                jdk.jlink requires jdk.internal.opt jrt:/jdk.internal.opt
                jdk.crypto.cryptoki requires jdk.crypto.ec jrt:/jdk.crypto.ec
                jdk.naming.rmi requires java.naming jrt:/java.naming
                jdk.naming.rmi requires java.rmi jrt:/java.rmi
                jdk.naming.dns requires java.naming jrt:/java.naming
                jdk.editpad requires java.desktop jrt:/java.desktop
                jdk.editpad requires jdk.internal.ed jrt:/jdk.internal.ed
                

                推荐答案

                随着更多的挖掘,我在 找到了解决方案https://developer.jboss.org/thread/278334 指向我 https://docs.jboss.org/author/display/WFLY10/Class+Loading+in+WildFly.文章有一个标题为访问 JDK 类"的部分,其中指出并非所有类默认都可用于部署,您需要将它们添加到 jboss-deployment-structure.xml 以使它们可用.

                With more digging I found the solution at https://developer.jboss.org/thread/278334 which pointed me to https://docs.jboss.org/author/display/WFLY10/Class+Loading+in+WildFly. The article has a section titled "Accessing JDK classes" which states that not all classes are available to deployment by default, and you need to add them to jboss-deployment-structure.xml to make them available.

                就我而言:

                <jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.1">
                    <deployment>
                        <dependencies>
                            <system export="true">
                                <paths>
                                    <path name="sun/reflect"/>
                                </paths>
                            </system>
                        </dependencies>
                    </deployment>
                </jboss-deployment-structure>
                

                此解决方案适用于

                • Wildfly 13,在 Java 10.0.2 上运行(9.0.4 也可以)
                • 使用 Java 8 编译的应用
                • Mockito 1.10.19(我尝试了 2.20.0 但出现了新错误)

                这篇关于Mockito、Java 9 和 java.lang.ClassNotFoundException:sun.reflect.ReflectionFactory的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Mockito,@InjectMocks 最终字段的奇怪行为 下一篇:如何在 Android 项目的 Java 模块上使用 Mockito 2 模拟

                相关文章

                最新文章

                  <tfoot id='BSspG'></tfoot>

                  <small id='BSspG'></small><noframes id='BSspG'>

                1. <i id='BSspG'><tr id='BSspG'><dt id='BSspG'><q id='BSspG'><span id='BSspG'><b id='BSspG'><form id='BSspG'><ins id='BSspG'></ins><ul id='BSspG'></ul><sub id='BSspG'></sub></form><legend id='BSspG'></legend><bdo id='BSspG'><pre id='BSspG'><center id='BSspG'></center></pre></bdo></b><th id='BSspG'></th></span></q></dt></tr></i><div id='BSspG'><tfoot id='BSspG'></tfoot><dl id='BSspG'><fieldset id='BSspG'></fieldset></dl></div>

                  <legend id='BSspG'><style id='BSspG'><dir id='BSspG'><q id='BSspG'></q></dir></style></legend>
                    <bdo id='BSspG'></bdo><ul id='BSspG'></ul>