I am seeing following exception when I try to use dynamic proxy
com.intellij.rt.execution.application.AppMain DynamicProxy.DynamicProxy
Exception in thread "main" java.lang.IllegalArgumentException: interface Interfaces.IPerson is not visible from class loader
at java.lang.reflect.Proxy.getProxyClass(Proxy.java:353)
at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:581)
at DynamicProxy.Creator.getProxy(Creator.java:18)
at DynamicProxy.DynamicProxy.main(DynamicProxy.java:54)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
Any idea what I need to do to resolve it
Best Answer
If this is web application, then you should use the web application classloader when creating dynamic proxy. So, for example instead of:
try:
For instance, hierarchy of tomcat class loaders (other web containers have similar) is following:
And it is the webapp classloader which contains classes and resources in the /WEB-INF/classes directory of your web application, plus classes and resources in JAR files under the /WEB-INF/lib directory of your web application.