IllegalAccessError when creating CGLIB proxies for package-private classes using Spring DevTools
See original GitHub issueI hit this error using gradle bootRun
when spring-boot-devtools
is on the classpath:
o.s.aop.framework.CglibAopProxy : Unable to proxy method [...] because it is package-visible across different ClassLoaders: All calls to this method via a proxy will NOT be routed to the target instance.
<snip>
java.lang.IllegalAccessError: class Foo$$EnhancerBySpringCGLIB$$8345c360 cannot access its superclass Foo
If I remove spring-boot-devtools
, the application starts fine. I’m guessing this is due to the classloader architecture of spring-boot-devtools
…
Issue Analytics
- State:
- Created 7 years ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
IllegalAccessError when creating CGLIB proxies for package ...
I hit this error using gradle bootRun when spring-boot-devtools is on the classpath: o.s.aop.framework.CglibAopProxy : Unable to proxy ...
Read more >CGLIB with spring throws IllegalAccessError - Stack Overflow
The issue is basically that Spring is instructing CGLIB to create the proxy class (subclass, com.company.int.components.core.registration.
Read more >ClassCastException occured on Solver.solve in spring boot
Now that I know that this error is related to spring-boot-devtools, and that the error will not occur if ... at org.springframework.cglib.proxy.
Read more >Bug List - Bugs - Eclipse
Let's make it more convenient to use. 2017-03-23 ... AJDT 2.2.3 (AJ 1.7.3) does not weaves classes in Kepler Java EE project with...
Read more >Difference between JDK dynamic proxy and CGLib proxy in ...
It can create proxy by subclassing. Spring uses CGLIB for proxy if class is not implementing interface. Sr. No. Key, JDK dynamic proxy,...
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
@kartoffelsup In your case the problem is because your application is split into multiple modules which can cause problems with DevTools’ restart class loader.
The proxy for BarServiceImpl is loaded by the restart class loader but BarServiceImpl itself is loaded by the app class loader. A package is scoped to the class loader that defined it so, in this case, we end up with two different
org.bar.devtools.autoconfig.demo
packages and a package-private type in one of those package is not visible to a type in the other of those packages.You can fix the problem by adding bar to the restart class loader using
META-INF/spring-devtools.properties
:Ahh, thank you @wilkinsona 😃! Sorry for the inconvenience.