Interface is not visible from ClassLoader when using a proxy?

前端 未结 3 653
面向向阳花
面向向阳花 2020-12-31 07:45

I am seeing following exception when I try to use dynamic proxy

 com.intellij.rt.execution.application.AppMain DynamicProxy.DynamicProxy
Exception in thread         


        
3条回答
  •  天涯浪人
    2020-12-31 08:09

    I had the same problem using spring boot, I solve it injecting ResourceLoader, getting its class loader.

    @Autowired
    private ResourceLoader resourceLoader;
    
    ....
    ClassLoader classLoader = resourceLoader.getClassLoader();
    ...
    
    
    Proxy.newProxyInstance(
      classLoader, //for example...
      new Class < ? >[] {MyInterface.class},
      new InvocationHandler() {
      // (...)
    });
    

提交回复
热议问题