In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Javassist how to dynamically modify code at runtime, I believe many inexperienced people are helpless about this, this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Javassist is a Java class handler commonly used to implement dynamic proxies. Used to implement proxy functionality in various frameworks.
Pros:
0 Ability to operate class
1 can modify class files at runtime
2 widely dependent (hibernate,mybatis will apply its jar package, no need to refer again)
Related code://Listen to port 8000, set//java -agentlib in startup parameters:jdwp=transport=dt_socket,server=y,suspend=n,address=8000HotSwapper hs = new HotSwapper(8000);// ClassPool cp = ClassPool.getDefault();//Get class String clsName = C2.C8.class.getName();CtClass cc = cp.get(clsName);//Get method CtMethod m = cc.getDeclaredMethod ("getSerial");//Rewrite method m.setBody("{ return getM(); }");//Call System.out.println(C2.C8.getM()) once;hs.reload(clsName, cc.toBytecode());//Call System.out.println(C2.C8.getM()) once more; Note:
0 JVM does not allow multiple versions of a class. Changing class requires attention.
1 Need to enable JPDA support Load class java -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=8000
2 Open JPDA will affect debug
After reading the above, do you know how to modify code dynamically at runtime in javassist? If you still want to learn more skills or want to know more related content, welcome to pay attention to the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.