﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-gembin-随笔分类-Spring</title><link>http://www.blogjava.net/gembin/category/34815.html</link><description>&lt;font color="red"&gt;OSGi, Eclipse Equinox, ECF, Virgo, Gemini,  Apache Felix, Karaf, Aires, Camel, Eclipse RCP&lt;/font&gt;&lt;br/&gt;&lt;br/&gt;
&lt;font color="green"&gt;HBase, Hadoop, ZooKeeper, Cassandra&lt;/font&gt;&lt;br/&gt;&lt;br/&gt;

&lt;font color="blue"&gt;Flex4, AS3, Swiz framework, GraniteDS, BlazeDS etc.&lt;/font&gt;&lt;br/&gt;&lt;br/&gt;
&lt;font color="black"&gt;
There is nothing that software can't fix. Unfortunately, there is also nothing that software can't completely fuck up. That gap is called talent.&lt;/font&gt;
&lt;br/&gt;&lt;br/&gt;

&lt;a href="http://about.me/gembin"&gt;About Me&lt;/a&gt;

&lt;script type="text/javascript" src="http://platform.linkedin.com/in.js"&gt;&lt;/script&gt;&lt;script type="in/share" data-counter="right"&gt;&lt;/script&gt;

</description><language>zh-cn</language><lastBuildDate>Thu, 03 May 2012 11:24:21 GMT</lastBuildDate><pubDate>Thu, 03 May 2012 11:24:21 GMT</pubDate><ttl>60</ttl><item><title>Spring AOP: JDK Dynamic Proxy vs. CGLib proxy</title><link>http://www.blogjava.net/gembin/archive/2012/05/03/377268.html</link><dc:creator>gembin</dc:creator><author>gembin</author><pubDate>Thu, 03 May 2012 05:16:00 GMT</pubDate><guid>http://www.blogjava.net/gembin/archive/2012/05/03/377268.html</guid><wfw:comment>http://www.blogjava.net/gembin/comments/377268.html</wfw:comment><comments>http://www.blogjava.net/gembin/archive/2012/05/03/377268.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/gembin/comments/commentRss/377268.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/gembin/services/trackbacks/377268.html</trackback:ping><description><![CDATA[<font color="#92a1d6" face="Arial, Tahoma, Helvetica, FreeSans, sans-serif" size="2"><span style="line-height: 18px; background-color: #ffffff;">Spring's AOP</span></font><span style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; background-color: #ffffff; ">&nbsp;is proxy-based. Spring provides&nbsp;</span><font color="#92a1d6" face="Arial, Tahoma, Helvetica, FreeSans, sans-serif" size="2"><span style="line-height: 18px; background-color: #ffffff;">two different options</span></font><span style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; background-color: #ffffff; ">&nbsp;to create the proxies. One is based on JDK dynamic proxies and works with interfaces, the other one utilizes CGLib and is based on classes. (That's why the property is called&nbsp;</span><span style="font-size: 13px; line-height: 18px; background-color: #ffffff; font-family: monospace; ">proxyTargetClass</span><span style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; background-color: #ffffff; ">&nbsp;respectively&nbsp;</span><span style="font-size: 13px; line-height: 18px; background-color: #ffffff; font-family: monospace; ">proxy-target-class</span><span style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; background-color: #ffffff; ">.) For the moment I just want to provide a quick summary on the pros and cons of both options:</span><br style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; background-color: #ffffff; " /><br style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; background-color: #ffffff; " /><span style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; background-color: #ffffff; ">JDK dynamic proxies:</span><br style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; background-color: #ffffff; " /><ul style="padding-top: 0px; padding-right: 2.5em; padding-bottom: 0px; padding-left: 2.5em; margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 18px; list-style-position: initial; list-style-image: initial; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; background-color: #ffffff; "><br /><li style="padding-top: 0.25em; padding-right: 0px; padding-bottom: 0.25em; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 0px; border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; ">The class&nbsp;<span style="font-style: italic; font-weight: bold; ">has</span>&nbsp;to implement interfaces. Otherwise you will get ClassCastExceptions saying that $Proxy0 can not be casted to the particular class.</li><br /><li style="padding-top: 0.25em; padding-right: 0px; padding-bottom: 0.25em; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 0px; border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; ">Eventually dynamic proxies force you to program to interfaces since you can not cast the proxy to the class - a feature I&nbsp;<span style="font-style: italic; font-weight: bold; ">really</span>&nbsp;like about them.</li><br /></ul><br style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; background-color: #ffffff; " /><span style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; background-color: #ffffff; ">CGLib proxies:</span><br style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; line-height: 18px; background-color: #ffffff; " /><ul style="padding-top: 0px; padding-right: 2.5em; padding-bottom: 0px; padding-left: 2.5em; margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 18px; list-style-position: initial; list-style-image: initial; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; background-color: #ffffff; "><br /><li style="padding-top: 0.25em; padding-right: 0px; padding-bottom: 0.25em; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 0px; border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; ">The proxies are created by sub-classing the actual class. This means wherever an instance of the class is used it is also possible to use the CGLib proxy.</li><br /><li style="padding-top: 0.25em; padding-right: 0px; padding-bottom: 0.25em; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 0px; border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; ">The class needs to provide a default constructor, i.e. without any arguments. Otherwise you'll get an IllegalArgumentException: "Superclass has no null constructors but no arguments were given." This makes constructor injection impossible.</li><br /><li style="padding-top: 0.25em; padding-right: 0px; padding-bottom: 0.25em; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 0px; border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; ">The proxying does not work with final methods since the proxy sub class can not override the class' implementation.</li><br /><li style="padding-top: 0.25em; padding-right: 0px; padding-bottom: 0.25em; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 0px; border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; ">The CGLib proxy is final, so proxying a proxy does not work. You will get an IllegalArgumentException saying "Cannot subclass final class $Proxy0". But this feature is usually not needed anyway.&nbsp;</li><br /><li style="padding-top: 0.25em; padding-right: 0px; padding-bottom: 0.25em; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 0px; border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; ">Since two objects are created (the instance of the class and the proxy as instance of a sub class) the constructor is called twice. In general this should not matter. I consider changing the class' state based on constructor calls a code smell anyway.</li><br /><li style="padding-top: 0.25em; padding-right: 0px; padding-bottom: 0.25em; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 0px; border-top-style: none; border-bottom-style: none; border-right-style: none; border-left-style: none; border-width: initial; border-color: initial; border-image: initial; ">You have CGLib as additional dependency.<br /><br />ref: &nbsp;<a href="http://static.springsource.org/spring/docs/3.1.1.RELEASE/spring-framework-reference/htmlsingle/spring-framework-reference.html#aop-introduction-proxies">http://static.springsource.org/spring/docs/3.1.1.RELEASE/spring-framework-reference/htmlsingle/spring-framework-reference.html#aop-introduction-proxies</a>&nbsp;<br /><br /><br /></li></ul><img src ="http://www.blogjava.net/gembin/aggbug/377268.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/gembin/" target="_blank">gembin</a> 2012-05-03 13:16 <a href="http://www.blogjava.net/gembin/archive/2012/05/03/377268.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>为Spring Security添加IP限制功能</title><link>http://www.blogjava.net/gembin/archive/2010/10/11/334456.html</link><dc:creator>gembin</dc:creator><author>gembin</author><pubDate>Mon, 11 Oct 2010 09:24:00 GMT</pubDate><guid>http://www.blogjava.net/gembin/archive/2010/10/11/334456.html</guid><wfw:comment>http://www.blogjava.net/gembin/comments/334456.html</wfw:comment><comments>http://www.blogjava.net/gembin/archive/2010/10/11/334456.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/gembin/comments/commentRss/334456.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/gembin/services/trackbacks/334456.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 为Spring Security添加IP限制功能&nbsp;&nbsp;<a href='http://www.blogjava.net/gembin/archive/2010/10/11/334456.html'>阅读全文</a><img src ="http://www.blogjava.net/gembin/aggbug/334456.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/gembin/" target="_blank">gembin</a> 2010-10-11 17:24 <a href="http://www.blogjava.net/gembin/archive/2010/10/11/334456.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>