Results 1 to 3 of 3

Thread: Getting class implementation from a proxy

Hybrid View

  1. #1
    Join Date
    Jul 2007
    Location
    Mauritius
    Posts
    127

    Default Getting class implementation from a proxy

    Hi guys,
    I am attempting to get the class implementation from a proxy, but I am failing to find the right way to do it.

    This is being done in a test and the proxy is actually cusAccLocSearchService


    Code:
             /** Inject Service to test */
    	@Resource(name = "cus_service_CustAccLocSearchService")
    	protected CusAccLocSearchService cusAccLocSearchService;
    and the service implementation is annotated with @Service.


    Can anyone of you point me to a piece of code that I can reuse (copy really ), and just be able to get the implementation out of the proxy?


    Thanks
    Kris

  2. #2
    Join Date
    Sep 2012
    Location
    Czech Republic
    Posts
    39

    Default

    If the proxy is Spring AOP proxy, try ((Advised) proxy).getTargetSource().getTarget();

  3. #3
    Join Date
    Jul 2007
    Location
    Mauritius
    Posts
    127

    Default Thanks

    Hi Libor,

    thanks for the reply. You solution works .

    Let me know what you bank account is and I'll put some money in. Just kidding . You deserve it though.


    I got misled when debugging, as you can see in the screen shot h is of type JdkDynamicAopProxy. But you cannot use that class as it has the default access modifier and can only be used by classes within its package.
    debug_view.PNG


    Thanks again
    Kris

Posting Permissions

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