报错:
①org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘globalTransactionScanner’ defined in class path resource [io/seata/spring/boot/autoconfigure/SeataAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [io.seata.spring.annotation.GlobalTransactionScanner]: Factory method ‘globalTransactionScanner’ threw exception; nested exception is java.lang.ExceptionInInitializerError
②Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain) throws java.lang.ClassFormatError accessible: module java.base does not “opens java.lang” to unnamed module @69453e37
解决方法:
这个错误通常是由于 Java 9 及以上版本引入的模块系统(JPMS)导致的,特别是在使用反射时访问某些受保护的类或方法。
要解决这个问题,可以尝试以下几种方法:
添加 JVM 启动参数:
在启动你的 Spring Boot 应用时,添加以下 JVM 参数来开放模块:
--add-opens java.base/java.lang=ALL-UNNAMED
具体操作方式因运行方式不同而异:
- 在 IDE 中(如 IntelliJ IDEA 或 Eclipse),你可以在运行配置中找到“VM options”或“Program arguments”选项,添加上述参数。
- 在命令行中,可以这样运行:
java --add-opens java.base/java.lang=ALL-UNNAMED -jar your-app.jar
具体添加方法步骤:
你可以在不同的环境中以不同的方式添加 --add-opens 参数。下面是几种常见的方法:
1. 在 IDE 中添加
IntelliJ IDEA
- 打开项目,点击顶部菜单的 Run。
- 选择 Edit Configurations。
- 在运行配置中,找到 VM options 输入框。
- 添加
--add-opens java.base/java.lang=ALL-UNNAMED,然后点击 OK。
Eclipse
- 右击你的项目,选择 Run As > Run Configurations。
- 选择你的 Java 应用配置。
- 在 Arguments 选项卡中,找到 VM arguments 输入框。
- 添加
--add-opens java.base/java.lang=ALL-UNNAMED,然后点击 Apply 和 Run。
2. 在命令行中添加
如果你是通过命令行运行 JAR 文件,可以在命令中直接添加参数。例如:
java --add-opens java.base/java.lang=ALL-UNNAMED -jar your-app.jar
3. 在构建工具中添加
如果你使用 Maven 或 Gradle,可以在构建配置中添加这个参数。
Maven
在 pom.xml 中,添加以下插件配置:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<fork>true</fork>
<compilerArgs>
<arg>--add-opens</arg>
<arg>java.base/java.lang=ALL-UNNAMED</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
</build>
Gradle
在 build.gradle 文件中,添加以下配置:
tasks.withType(JavaExec) {
jvmArgs '--add-opens', 'java.base/java.lang=ALL-UNNAMED'
}
按照你的项目环境选择合适的方法,添加完参数后重新运行你的应用。
1619

被折叠的 条评论
为什么被折叠?



