I am trying to use AOP with Java 9 modules. On application startup I get this issue. I tried with Spring version: 5.3.1 8 and 5.3.22
Seems like AOP is not yet Java 9 module compatible.
Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class com.sachin.controllers.TestControllers: Common causes of this problem include using a final class or a non-visible class; nested exception is org.springframework.cglib.core.CodeGenerationException: java.lang.IllegalAccessError-->superinterface check failed: class com.sachin.controllers.TestControllers$$EnhancerBySpringCGLIB$$48d20b1a (in module bnpl.web) cannot access class org.springframework.aop.framework.Advised (in unnamed module @0x163e4e87) because module bnpl.web does not read unnamed module @0x163e4e87 at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:209) ~[spring-aop-5.3.22.jar:5.3.22] at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110) ~[spring-aop-5.3.22.jar:5.3.22] at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.createProxy(AbstractAutoProxyCreator.java:480) ~[spring-aop-5.3.22.jar:5.3.22] at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.wrapIfNecessary(AbstractAutoProxyCreator.java:344) ~[spring-aop-5.3.22.jar:5.3.22] at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator.postProcessAfterInitialization(AbstractAutoProxyCreator.java:293) ~[spring-aop-5.3.22.jar:5.3.22] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:455) ~[spring-beans-5.3.22.jar:?] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1808) ~[spring-beans-5.3.22.jar:?] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.22.jar:?]
Comment From: SachinSharmaa
It works if I add --add-reads mymodule.name=ALL-UNNAMED. But I was expecting aop to be modularised.
Comment From: SachinSharmaa
Never mind worked when I added requires spring.aop to my module. I did not find this solution anywhere, also the stack trace did not have anything to suggest that. Maybe some documentation or error logging can be added for this.
Comment From: sbrannen
Never mind worked when I added requires spring.aop to my module.
Glad to hear that you sorted it you!
Maybe some documentation or error logging can be added for this.
We are considering providing documentation on using Spring with the Java module system in the Spring Framework 6.0 time frame.