Giter Club home page Giter Club logo

coders-dream-works's People

Contributors

zoeminghong avatar

Watchers

 avatar  avatar

coders-dream-works's Issues

UnsatisfiedDependencyException: Error creating bean with name

问题

使用动态代理的方式实例化接口,在获取bean对象的时候出现bean对象类型转换错误
java

原因

ClassLoader(类加载器)不同导致requiredType.isAssignableFrom(bean.getClass())中的requiredType与实际的类对象不是同一个指针。发现requiredType是使用restartClassLoader进行加载,而实际的类是使用appClassLoader进行加载。

解决方案

去除restartClassLoader加载器,该加载器是Springboot中的devtools依赖包中的,所以去除该依赖包就可以了。
restartClassLoader

java8 通过反射执行接口的default方法

问题

根据http://www.jianshu.com/p/63691220f81f进行处理,出现了java.lang.Class cannot be cast to java.lang.reflect.ParameterizedType问题

java

原因

返现这个问题直接调用下面的方法导致

(Class<E>) (((ParameterizedType) this.getClass().getGenericInterfaces()[0]).getActualTypeArguments()[0]);

由于使用了代理类,所以this是代理对象,而实际需要的是当前类的对象。

解决方案

if (Proxy.class.isAssignableFrom(this.getClass())) {
            return (Class<E>) (((ParameterizedType) this.getClass().getInterfaces()[0].getGenericInterfaces()[0]).getActualTypeArguments()[0]);
        } else {
            return (Class<E>) (((ParameterizedType) this.getClass().getGenericInterfaces()[0]).getActualTypeArguments()[0]);
        }

Unexpected end of file from server

问题

调用http请求,长时间没有数据返回,报Unexpected end of file from server; nested exception is java.net.SocketException: Unexpected end of file from server
java

原因

调用接口是没有正常response,由于服务器的网络等等问题导致

解决方案

提供稳定的运行环境

Caused by: java.net.SocketTimeoutException: Read timed out

问题

Caused by: java.net.SocketTimeoutException: Read timed out

Caused by: java.lang.RuntimeException: java.net.SocketTimeoutException: Read timed out

Caused by: com.netflix.client.ClientException: null

com.netflix.zuul.exception.ZuulException: Forwarding error

java

原因

zuul.read-timeout时间偏小

解决方案

zuul.read-timeout=12000

使用代理类需要考虑的场景

问题

存在一些接口的default方法、正常实例化对象、特殊处理等场景

java

原因

存在一些接口的default方法、正常实例化对象、特殊处理等场景

解决方案

if (!method.getDeclaringClass().isInterface() && !method.isDefault()) {
            // This proxy is class and method has not impl
            return method.invoke(this, args);
        } else if (method.isDefault()) {
            // This proxy is interface but method has impl
            return getMethodHandle(method).bindTo(proxy)
                    .invokeWithArguments(args);
        } else {
            // This proxy is interface
            return run(method, args);
        }

联系如下issue一起看
#1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.