当前位置:网站首页>Cglib dynamic proxy
Cglib dynamic proxy
2022-06-25 07:36:00 【Borny Ding Ding】
1、 explain
Dynamically generate a subclass of the proxy class , Subclass overrides all of the classes to be proxied final Methods . Provide proxies for classes that do not implement interfaces , yes jdk Dynamic agent is a good supplement . Application scenarios , for example aop、hibernate.
2、 Simple example
public class DogService {
public void sound() {
System.out.println("wang");
}
}DogService dogService = new DogService();
// cglib A dynamic proxy
Enhancer enhancer = new Enhancer();
enhancer.setClassLoader(dogService.getClass().getClassLoader());
enhancer.setSuperclass(dogService.getClass());
MethodInterceptor methodInterceptor = new MethodInterceptor() {
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy)
throws Throwable {
System.out.println("before");
Object invoke = method.invoke(dogService, args);
System.out.println("after");
return invoke;
}
};
enhancer.setCallback(methodInterceptor);
DogService dogServiceProxy = (DogService) enhancer.create();
dogServiceProxy.sound();test result
before
wang
after边栏推荐
- Weimeisi new energy rushes to the scientific innovation board: the annual revenue is 1.7 billion, and the book value of accounts receivable is nearly 400million
- 14 BS object Node name Name attrs string get node name attribute content
- 【批處理DOS-CMD命令-匯總和小結】-cmd擴展命令、擴展功能(cmd /e:on、cmd /e:off)
- 线程状态变化涉及哪些常用 API
- [batch dos-cmd command - summary and summary] - external command -cmd download command and packet capture command (WGet)
- [Batch dos - cmd Command - Summary and Summary] - cmd extension Command, extension Function (CMD / E: on, CMD / E: off)
- Alphassl wildcard certificate for one month
- 【批处理DOS-CMD命令-汇总和小结】-外部命令-cmd下载命令、抓包命令(wget)
- 5g private network market is in full swing, and it is crucial to solve deployment difficulties in 2022
- MySQL facet 01
猜你喜欢
![[batch dos-cmd command - summary and summary] - add comment command (REM or::)](/img/e9/151885ecd490b0aa83cce0f3a49124.png)
[batch dos-cmd command - summary and summary] - add comment command (REM or::)

Sichuan earth microelectronics high performance, high integration and low cost isolated 485 transceiver

One year's time and University experience sharing with CSDN

Debug through yalc before releasing NPM package

Evolution of Alibaba e-commerce architecture

鸿蒙页面菜单的选择

JMeter introduction practice ----- use of global variables and local variables

Weimeisi new energy rushes to the scientific innovation board: the annual revenue is 1.7 billion, and the book value of accounts receivable is nearly 400million

MCU IO explanation (pull-up pull-down quasi bidirectional input / output push-pull open drain)

Zhugeliang vs pangtong, taking distributed Paxos
随机推荐
Sichuan earth microelectronics high performance, high integration and low cost isolated 485 transceiver
lotus v1.16.0-rc3 calibnet
VectorDraw Web Library 10.10
Large funds support ecological construction, and Plato farm builds a real meta universe with Dao as its governance
[batch dos-cmd command - summary and summary] - application startup and call, service and process operation commands (start, call, and)
Cocos learning diary 3 - API acquisition nodes and components
【UVM入門 ===> Episode_9 】~ 寄存器模型、寄存器模型的集成、寄存器模型的常規方法、寄存器模型的應用場景
Kube scheduler source code analysis (1) - initialization and startup analysis
Don't you know the evolution process and principle of such a comprehensive redis cluster model?
诸葛亮 VS 庞统,拿下分布式 Paxos
CPDA|数据分析师成长之路如何起步?
【批处理DOS-CMD命令-汇总和小结】-外部命令-cmd下载命令、抓包命令(wget)
全局变量&局部变量
What common APIs are involved in thread state changes
What if there is no point in data visualization?
[leetcode] two num · sum of two numbers
Tempest HDMI leak receive 2
【批处理DOS-CMD命令-汇总和小结】-应用程序启动和调用、服务和进程操作命令(start、call、)
What is the difference between norflash and nandflash
Orcad Schematic常用功能