AspectJ proxy bean gives IllegalAccessException in Java 16
See original GitHub issueHere is a sample project which demonstrates the issue with SB 2.4 and JDK 16 https://github.com/EvgeniGordeev/spring-boot-java-16-aspectj-proxy-error.
The application cannot start due to:
Caused by: java.lang.IllegalAccessException: module java.base does not open java.lang to unnamed module @11dc3715
at java.base/java.lang.invoke.MethodHandles.privateLookupIn(MethodHandles.java:260) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:567) ~[na:na]
at org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:574) ~[spring-core-5.3.6.jar:5.3.6]
... 23 common frames omitted
Valid for beans with @Transactional
and when SpringBootApplication
combines @EnableAspectJAutoProxy
and
@EnableTransactionManagement
.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (4 by maintainers)
Top Results From Across the Web
AspectJ proxy bean gives IllegalAccessException in Java 16
@philwebb It looks like this is yet another case of a ClassLoader mismatch on proxy creation. This warning/exception will appear any time the ......
Read more >How to invoke spring bean method with all proxies/aspects?
Java : 11, Spring-boot: 2.5.3. I am trying to implement some annotation-based abstraction on event processing. I have created annotation ...
Read more >IllegalAccessException (Java SE 16 & JDK 16)
An IllegalAccessException is thrown when an application tries to reflectively create an instance (other than an array), set or get a field, ...
Read more >Spring JDK Proxies vs CGLIB vs AspectJ - Credera
It demonstrates that if you're using a JDK proxy and the join point annotation is present on the concrete implementation of a bean...
Read more >Before i use @Mapper(IntegerMapper.class) but now is ...
java.lang.IllegalArgumentException: A bean, int, was mapped which was not instantiable ... invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:621).
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m going to transfer this one to the Spring Framework team for assessment. Spring Boot isn’t actually involved in the proxy creation, it’s a framework concern. This looks similar to https://github.com/spring-projects/spring-framework/issues/26440 but there’s no
module-info
involved in your sample.I’m not sure how we can fix this one either. In this case
contextClass
isjava.lang.Object
sogetClassLoader()
returnsnull
. Theloader
argument is the app class loader (jdk.internal.loader.ClassLoaders$AppClassLoader
).As far as I can tell, the failure is specific to proxying of methods defined in the JDK such as
Object#toString
which is the method being called in the sample. CallingtestMethod()
on the proxied service doesn’t trigger the problem and works fine (once the sample’s dependencies have been updated a little so that a transaction manager is auto-configured).