Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3987290
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:06:58+00:00 2026-05-20T06:06:58+00:00

I am using the @AspectJ style for writing aspects, to handle logging in our

  • 0

I am using the @AspectJ style for writing aspects, to handle logging in our application. Basically I have a pointcut set up like so:

@Pointcut("call(public * com.example..*(..))")
public void logging() {}

and then a before and after advice like so:

@Before("logging()")
public void entering() {...}
...
@After("logging()")
public void exiting() {...}

I want to create a log in these methods in the following format:

logger.trace("ENTERING/EXITING [" className + "." + methodName "()]");

The problem is I don’t know how to get a reference to the class and method names. I have tried:

joinPoint.getThis().getClass()

but this seems to return the caller’s class name.

class A {
    public void a() {
        B.b();
    }
}


class B {
    public void b() {
        ...
    }
}

would result in the following log

ENTERING [A.b()]

can someone give some help on how to get the actual joinpoint class and method name

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T06:06:58+00:00Added an answer on May 20, 2026 at 6:06 am

    You need to use joinPoint.getTarget().getClass(). Since you are using advising a call join point, the object of your interest is the target of the call.

    Please note the API specification states:

    Returns the target object. This will always be the same object as that matched by the target pointcut designator. Unless you specifically need this reflective access, you should use the target pointcut designator to get at this object for better static typing and performance.

    Returns null when there is no target object.

    Blindly using joinPoint.getTarget().getClass() can result in a NullPointerException. Consider using the join point’s signature, such as:

    final Signature signature = joinPoint.getSignature();
    

    Then:

    final Class clazz = signature.getDeclaringType();
    

    Or if all you need is the class name:

    final String clazz = signature.getDeclaringTypeName();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have started using aspects for parameter validation in our development framework. It works
I have an application using AspectJ with load time weaving to advise various methods.
I am using org.aspectj.lang.annotation.Pointcut . I have an interface com.home.learn.Try. I want a pointcut
I have a case where I'd like to animate the zoom style of a
I have an image that I would like to display in a UITableViewCell using
I think about using AspectJ in an existing project. I have several pure Java
I have a style like this: .vertical-rotate{ filter: progid:DXImageTransform.Microsoft.Matrix(M11=0.00000000, M12=-1.00000000, M21=1.00000000, M22=0.00000000,DX=32,sizingMethod='auto expand'); }
Using online interfaces to a version control system is a nice way to have
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using JDeveloper , I started developing a set of web pages for a project

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.