'IllegalAccessError: ClassA and class B are in unnamed module of loader 'app'
I have a spring @Configuration bean which initializes a class A. This class A, in its constructor, calls another static method in class B. When spring initializes class A it eventually fails with java.lang.IllegalAccessError: class A tried to access method in class B (class A and classB are in unnamed module of loader 'app')
The class A and B are in present in different libraries, and I don't get any compilation issue at all.
Java version is 11, and the app uses spring boot 2.3.4-RELEASE.
I tried searching for answers but seem to find nothing on it. Can somebody please assist here?
Solution 1:[1]
Adding the following to the module-info.java
did the trick for me:
requires spring.core;
requires spring.beans;
requires java.instrument;
Solution 2:[2]
Class B is loaded by a jar which is coming as a transitive dependency to the project. Added the jar, which has class B, as a direct dependency solved the issue.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Vincz777 |
Solution 2 | Raj V |