问题描述:
此Class策略执行异常:java.lang.IllegalAccessError: class com.shebao.CqGjjJyImpl tried to access field com.shebao.CqGjjZyImpl.workOrder (com.shebao.CqGjjJyImpl is in unnamed module of loader com.shebao.utils.MyJavaClassLoader @3831e436; com.shebao.CqGjjZyImpl is in unnamed module of loader org.springframework.boot.loader.LaunchedURLClassLoader @c038203)
原因:
- CqGjjJyImpl继承了CqGjjZyImpl,前者是使用自定义类加载器加载的,后者是springboot类加载器加载的(在idea中测试是使用appclassloader加载的,但是打成jar包运行就是springboot加载器加载)。
- master中有该类,导致继承的时候会继承master中springboot类加载加载的类,而不是自定义类加载器加载的类。(将master上的代码删除即可)
待解决问题:
为什么使用不同的类加载器加载的类无法互相访问? 是不是类的级联规则?
结论:
- 通过idea执行方法,使用的类加载器都是系统类加载器AppClassLoader, 通过执行jar文件,系统类加载器还是系统类加载器,但是加载jar里面class的时候使用的是org.springframework.boot.loader.LaunchedURLClassLoader,所以在使用系统类加载器去加载User的时候就会报错,找不到这个类了!(blog.csdn.net/qq_38366063…))