title: Spring `superinterface check failed` when using Java modules (for Axon Framework Spring Boot app)
body: <p>I am currently experimenting with Spring Boot, the Axon Framework and java modules (using JDK 17).</p>
  <p>I have created a repo to illustrate the problem: <a href="https://github.com/vab2048/axon-spring-module-error" rel="nofollow noreferrer">here</a></p>
  <p>The problem is that the application does not start and I get the exception as follows:</p>
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'accountViewProjection' defined in file [C:\workspace\axon\_issue_replication_repos\axon-module-error\axon-example-app\build\classes\java\main\io\github\vab2048\axon\example_bug\app\query\account\AccountViewProjection.class]: Initialization of bean failed; nested exception is org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class io.github.vab2048.axon.example_bug.app.query.account.AccountViewProjection: 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--&gt;superinterface check failed: class io.github.vab2048.axon.example_bug.app.query.account.AccountViewProjection$$EnhancerBySpringCGLIB$$159eee6a (in module io.github.vab2048.axon.example_bug.app) cannot access class org.springframework.aop.framework.Advised (in unnamed module @0x732d0d24) because module io.github.vab2048.axon.example_bug.app does not read unnamed module @0x732d0d24
      at spring.beans@5.3.20/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:628) ~[spring-beans-5.3.20.jar:na]
      at spring.beans@5.3.20/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.20.jar:na]
      at spring.beans@5.3.20/org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) ~[spring-beans-5.3.20.jar:na]
      at spring.beans@5.3.20/org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-5.3.20.jar:na]
      at spring.beans@5.3.20/org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) ~[spring-beans-5.3.20.jar:na]
      at spring.beans@5.3.20/org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208) ~[spring-beans-5.3.20.jar:na]
      at spring.beans@5.3.20/org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:953) ~[spring-beans-5.3.20.jar:na]
      at spring.context@5.3.20/org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918) ~[spring-context-5.3.20.jar:na]
      at spring.context@5.3.20/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583) ~[spring-context-5.3.20.jar:na]
      at spring.boot@2.7.0/org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147) ~[spring-boot-2.7.0.jar:na]
      at spring.boot@2.7.0/org.springframework.boot.SpringApplication.refresh(SpringApplication.java:734) ~[spring-boot-2.7.0.jar:na]
      at spring.boot@2.7.0/org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408) ~[spring-boot-2.7.0.jar:na]
      at spring.boot@2.7.0/org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-2.7.0.jar:na]
      at spring.boot@2.7.0/org.springframework.boot.SpringApplication.run(SpringApplication.java:1306) ~[spring-boot-2.7.0.jar:na]
      at spring.boot@2.7.0/org.springframework.boot.SpringApplication.run(SpringApplication.java:1295) ~[spring-boot-2.7.0.jar:na]
      at io.github.vab2048.axon.example_bug.app/io.github.vab2048.axon.example_bug.app.AxonApplication.main(AxonApplication.java:10) ~[main/:na]
  Caused by: org.springframework.aop.framework.AopConfigException: Could not generate CGLIB subclass of class io.github.vab2048.axon.example_bug.app.query.account.AccountViewProjection: 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--&gt;superinterface check failed: class io.github.vab2048.axon.example_bug.app.query.account.AccountViewProjection$$EnhancerBySpringCGLIB$$159eee6a (in module io.github.vab2048.axon.example_bug.app) cannot access class org.springframework.aop.framework.Advised (in unnamed module @0x732d0d24) because module io.github.vab2048.axon.example_bug.app does not read unnamed module @0x732d0d24
      at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:209) ~[spring-aop-5.3.20.jar:5.3.20]
      at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:110) ~[spring-aop-5.3.20.jar:5.3.20]
      at org.axonframework.spring@4.5.9/org.axonframework.spring.config.AbstractAnnotationHandlerBeanPostProcessor.createAdapterProxy(AbstractAnnotationHandlerBeanPostProcessor.java:190) ~[axon-spring-4.5.9.jar:na]
      at org.axonframework.spring@4.5.9/org.axonframework.spring.config.AbstractAnnotationHandlerBeanPostProcessor.postProcessAfterInitialization(AbstractAnnotationHandlerBeanPostProcessor.java:89) ~[axon-spring-4.5.9.jar:na]
      at spring.beans@5.3.20/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(AbstractAutowireCapableBeanFactory.java:455) ~[spring-beans-5.3.20.jar:na]
      at spring.beans@5.3.20/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1808) ~[spring-beans-5.3.20.jar:na]
      at spring.beans@5.3.20/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:620) ~[spring-beans-5.3.20.jar:na]
      ... 15 common frames omitted
  Caused by: org.springframework.cglib.core.CodeGenerationException: java.lang.IllegalAccessError--&gt;superinterface check failed: class io.github.vab2048.axon.example_bug.app.query.account.AccountViewProjection$$EnhancerBySpringCGLIB$$159eee6a (in module io.github.vab2048.axon.example_bug.app) cannot access class org.springframework.aop.framework.Advised (in unnamed module @0x732d0d24) because module io.github.vab2048.axon.example_bug.app does not read unnamed module @0x732d0d24
      at spring.core@5.3.20/org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:512) ~[spring-core-5.3.20.jar:na]
      at spring.core@5.3.20/org.springframework.cglib.core.AbstractClassGenerator.generate(AbstractClassGenerator.java:363) ~[spring-core-5.3.20.jar:na]
      at spring.core@5.3.20/org.springframework.cglib.proxy.Enhancer.generate(Enhancer.java:585) ~[spring-core-5.3.20.jar:na]
      at spring.core@5.3.20/org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:110) ~[spring-core-5.3.20.jar:na]
      at spring.core@5.3.20/org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData$3.apply(AbstractClassGenerator.java:108) ~[spring-core-5.3.20.jar:na]
      at spring.core@5.3.20/org.springframework.cglib.core.internal.LoadingCache$2.call(LoadingCache.java:54) ~[spring-core-5.3.20.jar:na]
      at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
      at spring.core@5.3.20/org.springframework.cglib.core.internal.LoadingCache.createEntry(LoadingCache.java:61) ~[spring-core-5.3.20.jar:na]
      at spring.core@5.3.20/org.springframework.cglib.core.internal.LoadingCache.get(LoadingCache.java:34) ~[spring-core-5.3.20.jar:na]
      at spring.core@5.3.20/org.springframework.cglib.core.AbstractClassGenerator$ClassLoaderData.get(AbstractClassGenerator.java:134) ~[spring-core-5.3.20.jar:na]
      at spring.core@5.3.20/org.springframework.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:319) ~[spring-core-5.3.20.jar:na]
      at spring.core@5.3.20/org.springframework.cglib.proxy.Enhancer.createHelper(Enhancer.java:572) ~[spring-core-5.3.20.jar:na]
      at spring.core@5.3.20/org.springframework.cglib.proxy.Enhancer.createClass(Enhancer.java:419) ~[spring-core-5.3.20.jar:na]
      at org.springframework.aop.framework.ObjenesisCglibAopProxy.createProxyClassAndInstance(ObjenesisCglibAopProxy.java:57) ~[spring-aop-5.3.20.jar:5.3.20]
      at org.springframework.aop.framework.CglibAopProxy.getProxy(CglibAopProxy.java:206) ~[spring-aop-5.3.20.jar:5.3.20]
      ... 21 common frames omitted
  Caused by: java.lang.IllegalAccessError: superinterface check failed: class io.github.vab2048.axon.example_bug.app.query.account.AccountViewProjection$$EnhancerBySpringCGLIB$$159eee6a (in module io.github.vab2048.axon.example_bug.app) cannot access class org.springframework.aop.framework.Advised (in unnamed module @0x732d0d24) because module io.github.vab2048.axon.example_bug.app does not read unnamed module @0x732d0d24
      at java.base/java.lang.ClassLoader.defineClass0(Native Method) ~[na:na]
      at java.base/java.lang.System$2.defineClass(System.java:2307) ~[na:na]
      at java.base/java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClass(MethodHandles.java:2439) ~[na:na]
      at java.base/java.lang.invoke.MethodHandles$Lookup$ClassDefiner.defineClass(MethodHandles.java:2416) ~[na:na]
      at java.base/java.lang.invoke.MethodHandles$Lookup.defineClass(MethodHandles.java:1843) ~[na:na]
      at java.base/jdk.internal.reflect.GeneratedMethodAccessor33.invoke(Unknown Source) ~[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:568) ~[na:na]
      at spring.core@5.3.20/org.springframework.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:507) ~[spring-core-5.3.20.jar:na]
      ... 35 common frames omitted
  </code></pre>
  <p>The offending code seems to to be in <code>io.github.vab2048.axon.example_bug.app.query.account.AccountViewProjection</code>:</p>
  <pre class="lang-java prettyprint-override"><code>    @QueryHandler
      public AccountView getAccount(GetAccountView query) {
          log.debug(&quot;Handling: {}&quot;, query);
          return repository.findById(query.id()).orElseThrow();
      }
  </code></pre>
  <p>It is the Axon annotation <code>@QueryHandler</code> which causes it (you can verify this by commenting it out and then everything works). This is strange because none of the other Axon annotations cause this problem. The package itself is both exported and open in the <code>module-info.java</code> file.</p>
  <p>What am I doing wrong? I am aware there may be command line arguments which may be added to solve this issue but am not sure what exactly to use (ideally I shouldn't have to give any command line arguments at all).</p>