So idea is to write a code which would add some predefined code snippets
eg I want to
Generate class field com.ck.MyClass.DEBUGGER
initialized as org.apache.commons.logging.LogFactory.getLog("DEBUGGER." + MyClass.CNAME);
add these below lines at entry point and exit point of all methods except constructors in a class through java code for all the classes present in my project
final String methodName = "process()"; if (MyClass.DEBUGGER.isDebugEnabled()) { MyClass.DEBUGGER.debug(CommonLoggingConstants.METHOD_ENTRY + MyClass.CNAME + CommonLoggingConstants.HASH + methodName); }
What would be the best approach and API to address this requirement?
Yo can use Aspect Oriented Programming in java to do anything before and after of any function call in java.
Follow the follwing link to implement it. You can use without Spring also. http://ganeshghag.blogspot.in/2012/10/demystifying-aop-getting-started-with.html
http://kamalmeet.com/tag/aop-2/
You could try to use AOP to intercept all the methods in your application and achieve your goal. You can read more about it here .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.