一、该问题的重现步骤是什么?
复现代码如下
package org.springblade.test;
import lombok.Data;
import org.springblade.core.tool.utils.BeanUtil;
import java.io.Serial;
import java.io.Serializable;
public class BeanUtilTest {
public static void main(String[] args) {
A a = new A();
a.setId(1L);
a.setIsDeleted(0);
BeanUtil.copy(a, B.class);
}
@Data
public static class A implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private Long id;
private Integer isDeleted;
}
@Data
public static class B implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
private Long id;
private Integer isDeleted;
}
}
二、你期待的结果是什么?实际看到的又是什么?
期待结果:代码正常运行
实际结果:代码无法正常运行
三、你正在使用的是什么产品,什么版本?在什么操作系统上?
产品: bladex-boot
版本:4.1.0.RELEASE
系统:Windows 11
四、请提供详细的错误堆栈信息,这很重要。
Exception in thread "main" org.springframework.cglib.core.ReflectUtils$2: No compatible defineClass mechanism detected: JVM should be started with --add-opens=java.base/java.lang=ALL-UNNAMED for ClassLoader.defineClass to be accessible. On the module path, you may not be able to define this CGLIB-generated class at all.
at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:547)
at org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:371)
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.lambda$new$1(AbstractClassGenerator.java:107)
at org.springframework.cglib.core.internal.LoadingCache.lambda$createEntry$1(LoadingCache.java:52)
at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
at org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:57)
at org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34)
at org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:130)
at org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:317)
at org.springblade.core.tool.beans.BladeBeanCopier$Generator.create(BladeBeanCopier.java:147)
at org.springblade.core.tool.beans.BladeBeanCopier.lambda$create$0(BladeBeanCopier.java:88)
at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1708)
at org.springblade.core.tool.beans.BladeBeanCopier.create(BladeBeanCopier.java:82)
at org.springblade.core.tool.beans.BladeBeanCopier.create(BladeBeanCopier.java:76)
at org.springblade.core.tool.utils.BeanUtil.copy(BeanUtil.java:163)
at org.springblade.core.tool.utils.BeanUtil.copy(BeanUtil.java:142)
at org.springblade.test.BeanUtilTest.main(BeanUtilTest.java:22)
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 @79b06cab
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:200)
at java.base/java.lang.reflect.Method.setAccessible(Method.java:194)
at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:505)
... 16 more
Process finished with exit code 1
五、若有更多详细信息,请在下面提供。
报错的第一行已经给你提示了,适当的时候建议多多百度和谷歌。90%的报错都能搜到解决方案。
解决方案:https://www.kancloud.cn/smallchill/blade/3197986
这样固然可以解决,但这不是破坏了模块的隔离性了吗?我的想法是BeanUtil工具类本身去解决
扫一扫访问 Blade技术社区 移动端