Announcement Announcement Module
Collapse
No announcement yet.
Getting the real class name from proxies Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting the real class name from proxies

    I have a simple beans with interceptors bound to them.

    My code is :

    Person person1 = (Person) beanFactory.getBean("person1");
    Person person2 = (Person) beanFactory.getBean("person2");

    System.out.println("person1: " + person1.getClass().getName());
    System.out.println("person2: " + person2.getClass().getName());

    It prints out:

    person1: $Proxy0
    person2: PersonImpl$$EnhancerByCGLIB$$dbf2c774

    which is what I expected since my application context has been configured as such.

    However, how do I get the "actual" class name (eg. PersonImpl?) from the proxied object?

    Dino

  • #2
    This should help....

    Dino,

    This should help in returning the name of the class that you are looking for :

    ((org.springframework.aop.framework.Advised)person 1).getTargetSource().getTarget()

    Thanks,
    Amit

    Comment


    • #3
      Re: This should help....

      Originally posted by chhajed
      ((org.springframework.aop.framework.Advised)person 1).getTargetSource().getTarget()
      I'm not sure if this still works if there is more than one interceptor. I would guess that from the first interceptor you get the class of the second one. Not tested, though.

      Regards,
      Andreas

      Comment


      • #4
        it should work...

        it should work even if you have multiple interceptors. I have tested the same.

        Comment


        • #5
          Re: This should help....

          Originally posted by chhajed
          Dino,

          This should help in returning the name of the class that you are looking for :

          ((org.springframework.aop.framework.Advised)person 1).getTargetSource().getTarget()

          Thanks,
          Amit
          It does. Thanks Amit.

          Dino

          Comment

          Working...
          X