All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.nntk.restplus.aop.RestPlusAopProxyFactory Maven / Gradle / Ivy

package com.nntk.restplus.aop;

import org.springframework.beans.factory.FactoryBean;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class RestPlusAopProxyFactory implements FactoryBean, InvocationHandler {

    private Class interfaceClass;

    public Class getInterfaceClass() {
        return interfaceClass;
    }

    public void setInterfaceClass(Class interfaceClass) {
        this.interfaceClass = interfaceClass;
    }

    @Override
    public T getObject() throws Exception {
        final Class[] interfaces = {interfaceClass};
        return (T) Proxy.newProxyInstance(this.getClass().getClassLoader(), interfaces, this);
    }

    @Override
    public Class getObjectType() {
        return interfaceClass;
    }

    @Override
    public boolean isSingleton() {
        return true;
    }

    /**
     * 真正执行的方法,会被aop拦截
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        return "invoke " + interfaceClass.getName() + "." + method.getName() + " , do anything ..";
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy