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

com.gitee.huanminabc.utils_common.obj.proxy.cglib.ProxyCglibInstance Maven / Gradle / Ivy

There is a newer version: 1.0.5-RELEASE
Show newest version
package com.gitee.huanminabc.utils_common.obj.proxy.cglib;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;

public class ProxyCglibInstance {


    public static  T getObject(Class target, MethodInterceptor invocationHandler) {
        //1.工具类
        Enhancer en = new Enhancer();
        //2.设置父类
        en.setSuperclass(target);
        //3.设置回调函数
        en.setCallback(invocationHandler);
        //4.创建子类(代理对象)
        return (T)en.create();
    }

    public static  T getObject(Object target, MethodInterceptor invocationHandler) {
        //1.工具类
        Enhancer en = new Enhancer();
        //2.设置父类
        en.setSuperclass(target.getClass());
        //3.设置回调函数
        en.setCallback(invocationHandler);
        //4.创建子类(代理对象)
        return (T)en.create();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy