简体   繁体   English

java在方法返回之前执行钩子代码

[英]java execute hook code before method return

I would like to have a post hook that is run before a method return. 我想有一个在方法返回之前运行的post钩子。 It should be possible add a hook to any method without modifying existing code. 应该可以在不修改现有代码的情况下将钩子添加到任何方法。 Is there a tool or technology that helps realise this? 有没有工具或技术可以帮助实现这一目标? Is javassist a candidate here? Javasist是这里的候选人吗? If yes, how to pass parameters to the hook? 如果是,如何将参数传递给钩子? Ideally whatever the method returns should be passed as parameter to the hook. 理想情况下,无论方法返回什么,都应将其作为参数传递给挂钩。

Yes, the technique is called byte code engineering. 是的,该技术称为字节码工程。 There are several popular tools. 有几种流行的工具。 The most famous higher level tool is called AspectJ. 最著名的高级工具称为AspectJ。

However there are lower level tools like CGLIB, Javassiste, BCEL. 但是,还有一些较低级别的工具,例如CGLIB,Javassiste,BCEL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Java 注解在方法前后执行代码 - Java annotation to execute code before and after method Java注释在方法之前和之后执行一些代码 - Java annotation to execute some code before and after method Java:强制方法的客户端在返回之前执行代码 - Java: Force Client of Method to Execute Code Before Returning 在方法之前和之后执行代码? - Execute code before and after method? Java并发-在调用`ExecutorService#execute`之前添加一个Shutdown挂钩 - Java Concurrency - Adding a Shutdown hook before calling `ExecutorService#execute` 在执行方法之前使用注释执行代码 - Execute code using annotations before the method is executed 服务页面之前的Java Servlet执行方法 - Java Servlet execute method before serving page 通过在Java中提供我的自定义注释,可以在执行任何方法之前和之后执行一些代码 - execute some code before and after of any method execution only by giving my custom annotation in java java的this()构造函数重载,如何在this()之前执行代码 - java Constructor overload with this(), how to execute code before this() 如何在Java中的gRPC方法调用的钩子之前和之后添加? - How to add before and after hook for gRPC method call in Java?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM