![](https://img.haomeiwen.com/i27194087/8dc4e85b79568ea4.png)
原因:这是jdk版本兼容问题。jdk8的反射相关功能在jdk9之后被限制。
为了兼容旧版本,只需在启动时增加参数来开启默认不被允许的行为:
--add-opens java.base/java.lang=ALL-UNNAMED
因为我们的问题是在测试阶段发生,所以在pom.xml的maven-surefire-plugin插件中加入黑体的内容。关于插件的作用,见官网https://maven.apache.org/surefire/maven-surefire-plugin/
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<reuseForks>true</reuseForks>
<forkCount>1</forkCount>
<argLine>
-Dio.netty.tryReflectionSetAccessible=true --add-opens java.base/jdk.internal.misc=ALL-UNNAMED
--add-opens java.base/java.lang=ALL-UNNAMED
--add-opens java.base/java.lang.reflect=ALL-UNNAMED
</argLine>
</configuration>
</plugin>
网友评论