Results 1 to 5 of 5

Thread: Getting the real class name from proxies

  1. #1
    Join Date
    Aug 2004
    Posts
    107

    Default 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. #2
    Join Date
    Jul 2005
    Posts
    8

    Default 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

  3. #3
    Join Date
    Aug 2004
    Posts
    2,715

    Default Re: This should help....

    Quote 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

  4. #4
    Join Date
    Jul 2005
    Posts
    8

    Default it should work...

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

  5. #5
    Join Date
    Aug 2004
    Posts
    107

    Default Re: This should help....

    Quote 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

Similar Threads

  1. Order of Bean definitions matters?
    By cfuser in forum Container
    Replies: 2
    Last Post: Oct 21st, 2005, 10:29 AM
  2. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  3. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  4. Replies: 3
    Last Post: Sep 4th, 2005, 11:11 PM
  5. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •