I have implemented AspectJ in my application in Spring MVC framework.I can track entry point and exit point of the function calls, but unable to get the actual line number from the source file.It's showing the line number of the Logger class where pointcuts and advices are placed.
Asked
Active
Viewed 1,081 times
2 Answers
1
Maybe your problem ist similar to this one, so hopefully the solution is the same for you:
joinPoint.getSourceLocation().getLine()
This works for real AspectJ (via LTW), but maybe not for Spring AOP which is just some kind of proxy-based "AOP lite" framework. For more information about how to configure Spring for AspectJ see the user manual, section 10.8, Using AspectJ with Spring applications.
-
-
Read my answer here and the linked one carefully, and you will know what is wrong. By the way, "giving me exception" is not very descriptive. – kriegaex Jan 23 '16 at 14:43
0
I do not know if there is a special AspectJ feature for this task, if not then you could obtain a StackTrace and then use StackTraceElement.getLineNumber()
.
//StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
Exception e =...
e.getStackTraceElement[]
stackTrace[stackTrace.length - 1].getLineNumber();

Ralph
- 118,862
- 56
- 287
- 383
-
This process is giving me all the details of exception from spring framework and servlet except the actual line where error occurred .I am getting $$EnhancerByCGLIB$$1a42e2f0 with the class where exception occurred ,but not the line of exception. – 619 Jan 15 '16 at 13:11
-