<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: How To Acess Target Object Behind a Spring Proxy</title>
	<atom:link href="http://www.techper.net/2009/06/05/how-to-acess-target-object-behind-a-spring-proxy/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.techper.net/2009/06/05/how-to-acess-target-object-behind-a-spring-proxy/</link>
	<description>About Technology in My Life</description>
	<lastBuildDate>Tue, 24 Jan 2012 17:27:15 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Unit testing transactions and optimistic locking with Spring and JUnit &#124; freestyle developments</title>
		<link>http://www.techper.net/2009/06/05/how-to-acess-target-object-behind-a-spring-proxy/comment-page-1/#comment-63715</link>
		<dc:creator>Unit testing transactions and optimistic locking with Spring and JUnit &#124; freestyle developments</dc:creator>
		<pubDate>Tue, 24 Jan 2012 17:27:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=217#comment-63715</guid>
		<description>[...] default &#8211; yes I realise you can get Spring to proxy the target class using CGLIB). I found this blog post which explains how to get at the target object behind a Spring proxy. I converted it to [...]</description>
		<content:encoded><![CDATA[<p>[...] default &#8211; yes I realise you can get Spring to proxy the target class using CGLIB). I found this blog post which explains how to get at the target object behind a Spring proxy. I converted it to [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bertolami</title>
		<link>http://www.techper.net/2009/06/05/how-to-acess-target-object-behind-a-spring-proxy/comment-page-1/#comment-49869</link>
		<dc:creator>Bertolami</dc:creator>
		<pubDate>Tue, 10 May 2011 10:46:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=217#comment-49869</guid>
		<description>Suggest you to use recursion because the proxies may be nested: 

	@SuppressWarnings({&quot;unchecked&quot;})
	private  T getTargetObject(Object proxy, Class targetClass) throws Exception {
	  while( (AopUtils.isJdkDynamicProxy(proxy)))  {
	    return (T) getTargetObject(((Advised)proxy).getTargetSource().getTarget(), targetClass);
	  } 
	  return (T) proxy; // expected to be cglib proxy then, which is simply a specialized class
	}</description>
		<content:encoded><![CDATA[<p>Suggest you to use recursion because the proxies may be nested: </p>
<p>	@SuppressWarnings({&#8220;unchecked&#8221;})<br />
	private  T getTargetObject(Object proxy, Class targetClass) throws Exception {<br />
	  while( (AopUtils.isJdkDynamicProxy(proxy)))  {<br />
	    return (T) getTargetObject(((Advised)proxy).getTargetSource().getTarget(), targetClass);<br />
	  }<br />
	  return (T) proxy; // expected to be cglib proxy then, which is simply a specialized class<br />
	}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: logan</title>
		<link>http://www.techper.net/2009/06/05/how-to-acess-target-object-behind-a-spring-proxy/comment-page-1/#comment-39652</link>
		<dc:creator>logan</dc:creator>
		<pubDate>Mon, 07 Jun 2010 14:28:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=217#comment-39652</guid>
		<description>You have have spring generate a proxy that is a true subclass of your bean. 

Make sure that version 2.2 of cglib is on your class path. Once you have that, you need to force spring to generate a subclass of your bean. This is done with the following attribute in your config xml.



Now the bean can be cast to the appropriate class without any AOP silliness. You can read more about it here.

http://static.springsource.org/spring/docs/2.5.x/reference/aop.html#aop-proxying</description>
		<content:encoded><![CDATA[<p>You have have spring generate a proxy that is a true subclass of your bean. </p>
<p>Make sure that version 2.2 of cglib is on your class path. Once you have that, you need to force spring to generate a subclass of your bean. This is done with the following attribute in your config xml.</p>
<p>Now the bean can be cast to the appropriate class without any AOP silliness. You can read more about it here.</p>
<p><a href="http://static.springsource.org/spring/docs/2.5.x/reference/aop.html#aop-proxying" rel="nofollow">http://static.springsource.org/spring/docs/2.5.x/reference/aop.html#aop-proxying</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: jcesarperez</title>
		<link>http://www.techper.net/2009/06/05/how-to-acess-target-object-behind-a-spring-proxy/comment-page-1/#comment-39582</link>
		<dc:creator>jcesarperez</dc:creator>
		<pubDate>Thu, 03 Jun 2010 14:16:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=217#comment-39582</guid>
		<description>Brave! Great explanation and great solution for the problem.

Thank you very much.
Julio.</description>
		<content:encoded><![CDATA[<p>Brave! Great explanation and great solution for the problem.</p>
<p>Thank you very much.<br />
Julio.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: polesen</title>
		<link>http://www.techper.net/2009/06/05/how-to-acess-target-object-behind-a-spring-proxy/comment-page-1/#comment-21344</link>
		<dc:creator>polesen</dc:creator>
		<pubDate>Fri, 10 Jul 2009 13:32:04 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=217#comment-21344</guid>
		<description>Nice!</description>
		<content:encoded><![CDATA[<p>Nice!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeoffrey</title>
		<link>http://www.techper.net/2009/06/05/how-to-acess-target-object-behind-a-spring-proxy/comment-page-1/#comment-21337</link>
		<dc:creator>Jeoffrey</dc:creator>
		<pubDate>Fri, 10 Jul 2009 12:29:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=217#comment-21337</guid>
		<description>You could also write it in a more readable way like this. 

@Override
protected void onSetUp() throws Exception {
  FooBeanImpl fooBeanImpl = getTargetObject(fooBean);
  fooBeanImpl.setBarRepository(new MyStubBarRepository());
}</description>
		<content:encoded><![CDATA[<p>You could also write it in a more readable way like this. </p>
<p>@Override<br />
protected void onSetUp() throws Exception {<br />
  FooBeanImpl fooBeanImpl = getTargetObject(fooBean);<br />
  fooBeanImpl.setBarRepository(new MyStubBarRepository());<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: polesen</title>
		<link>http://www.techper.net/2009/06/05/how-to-acess-target-object-behind-a-spring-proxy/comment-page-1/#comment-21326</link>
		<dc:creator>polesen</dc:creator>
		<pubDate>Fri, 10 Jul 2009 10:56:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=217#comment-21326</guid>
		<description>Cool. That really works, though it is kind of strange syntax. 

Sometimes I have the feeling that Java generics do really shitty things to code readability.</description>
		<content:encoded><![CDATA[<p>Cool. That really works, though it is kind of strange syntax. </p>
<p>Sometimes I have the feeling that Java generics do really shitty things to code readability.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeoffrey</title>
		<link>http://www.techper.net/2009/06/05/how-to-acess-target-object-behind-a-spring-proxy/comment-page-1/#comment-21322</link>
		<dc:creator>Jeoffrey</dc:creator>
		<pubDate>Fri, 10 Jul 2009 10:13:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=217#comment-21322</guid>
		<description>Ah I see there is something missing in my code snippet, probably filtered because it looks like xml/html :-)
Lets see if this will work.

@Override
protected void onSetUp() throws Exception {
this.&lt;FooBeanImpl&gt;getTargetObject(fooBean).setBarRepository(new MyStubBarRepository());
}</description>
		<content:encoded><![CDATA[<p>Ah I see there is something missing in my code snippet, probably filtered because it looks like xml/html <img src='http://www.techper.net/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /><br />
Lets see if this will work.</p>
<p>@Override<br />
protected void onSetUp() throws Exception {<br />
this.&lt;FooBeanImpl&gt;getTargetObject(fooBean).setBarRepository(new MyStubBarRepository());<br />
}</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: polesen</title>
		<link>http://www.techper.net/2009/06/05/how-to-acess-target-object-behind-a-spring-proxy/comment-page-1/#comment-21308</link>
		<dc:creator>polesen</dc:creator>
		<pubDate>Fri, 10 Jul 2009 08:22:49 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=217#comment-21308</guid>
		<description>Jeoffrey, glad it could help you.

I don&#039;t follow about removing the targetClass param. If I do so, the type parameter T does not resolve to the type of the bean, hence I cannot call setBarRepository on it. If you have it working without that extra param together with a type param, could you the post the getTargetObject method here?</description>
		<content:encoded><![CDATA[<p>Jeoffrey, glad it could help you.</p>
<p>I don&#8217;t follow about removing the targetClass param. If I do so, the type parameter T does not resolve to the type of the bean, hence I cannot call setBarRepository on it. If you have it working without that extra param together with a type param, could you the post the getTargetObject method here?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeoffrey</title>
		<link>http://www.techper.net/2009/06/05/how-to-acess-target-object-behind-a-spring-proxy/comment-page-1/#comment-21298</link>
		<dc:creator>Jeoffrey</dc:creator>
		<pubDate>Fri, 10 Jul 2009 07:21:38 +0000</pubDate>
		<guid isPermaLink="false">http://www.techper.net/?p=217#comment-21298</guid>
		<description>Thanks for the example it&#039;s exactly what I&#039;m looking for. 

I might have an answer to your first question. 
You can remove the targetClass parameter from the getTargetObject method. You would have to call the getTargetObject as follows.

@Override  
protected void onSetUp() throws Exception {  
   this.getTargetObject(fooBean).setBarRepository(new MyStubBarRepository());  
}

Greetings</description>
		<content:encoded><![CDATA[<p>Thanks for the example it&#8217;s exactly what I&#8217;m looking for. </p>
<p>I might have an answer to your first question.<br />
You can remove the targetClass parameter from the getTargetObject method. You would have to call the getTargetObject as follows.</p>
<p>@Override<br />
protected void onSetUp() throws Exception {<br />
   this.getTargetObject(fooBean).setBarRepository(new MyStubBarRepository());<br />
}</p>
<p>Greetings</p>
]]></content:encoded>
	</item>
</channel>
</rss>

