<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Path to Zen &#187; spring</title>
	<atom:link href="http://www.digizenstudio.com/blog/categories/java/spring/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.digizenstudio.com/blog</link>
	<description>Jing Xue's Weblog</description>
	<lastBuildDate>Tue, 01 Jun 2010 01:40:50 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The self-calling limitation in Spring-AOP and one unintrusive solution</title>
		<link>http://www.digizenstudio.com/blog/2007/05/29/the-self-calling-limitation-in-spring-aop-and-one-unintrusive-solution/</link>
		<comments>http://www.digizenstudio.com/blog/2007/05/29/the-self-calling-limitation-in-spring-aop-and-one-unintrusive-solution/#comments</comments>
		<pubDate>Wed, 30 May 2007 00:45:52 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[aop]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/2007/05/29/the-self-calling-limitation-in-spring-aop-and-one-unintrusive-solution/</guid>
		<description><![CDATA[Spring-AOP is implemented by creating proxies decorating the target bean. One typical gotcha from using these proxies, for instance, in declarative transaction management, is the proxy can't intercept a call made from one method to another on the same target object (typically a service bean), even though both methods are supposed to be wrapped by [...]]]></description>
			<content:encoded><![CDATA[<p>Spring-AOP is implemented by creating proxies decorating the target bean. One typical gotcha from using these proxies, for instance, in declarative transaction management, is the proxy can't intercept a call made from one method to another on the same target object (typically a service bean), even though both methods are supposed to be wrapped by the proxy.<span id="more-135"></span></p>
<p>One obvious solution to the problem is to always explicitly get the bean reference from the Spring context and then call the method on it, instead of calling the method on 'this'. For example, instead of <code>this.anotherServiceMethod()</code>, do:</p>
<div class="igBar"><span id="ljava-3"><a href="#" onclick="javascript:showPlainTxt('java-3'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div id="java-3">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// get hold of the application context either through</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// a singleton locator or through a private reference, then</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">context.<span style="color: #006600;">getBean</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"aServiceBean"</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">anotherServiceMethod</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>It's an easy solution, but one that doesn't come without a few nuisances. For instance, it adds to your service bean some compile-time dependencies on Spring classes that wouldn't have been necessary otherwise.</p>
<p>One less intrusive solution I've come up with is a <a href='http://www.digizenstudio.com/blog/wp-content/uploads/2007/05/adviceskippinginjector.java' title='AdviceSkippingInjector.java'><code>AdviceSkippingInjector.java</code></a> that injects the reference to any proxied Spring bean into a property on the "raw" bean, i.e., the object prior to being wrapped in the proxy.</p>
<p>To use it, add a <code>proxiedSelf</code> property to the service bean (it doesn't have to be on any public interface), add this to your context file:</p>
<div class="igBar"><span id="lxml-4"><a href="#" onclick="javascript:showPlainTxt('xml-4'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-4">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"aService"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"your.proxied.service.Bean"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"ProxySkippingInjector"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"com.digizen.commons.spring.AdviceSkippingInjector"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"beanProperties"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;map<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;entry</span> <span style="color: #000066;">key</span>=<span style="color: #ff0000;">"aService"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"proxiedSelf"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/map<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>In the map <code>beanProperties</code>, each key is a bean name defined in the context, and the corresponding value a property name on the bean. At run-time, if the <code>AdviceSkippingInjector</code> sees a bean name in its map, it will drill into the proxies, find the reference to the original bean, and inject the reference to the proxy into the original bean's <code>proxiedSelf</code> property.</p>
<p>This solution is unintrusive because the service bean remains unaware of any of the plumbing work. All the wiring is done in the application context. In fact, the service bean isn't even necessarily aware that <code>proxiedSelf</code>, despite the name, points to its "proxied self".</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2007/05/29/the-self-calling-limitation-in-spring-aop-and-one-unintrusive-solution/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Programmatically Build a Spring Application Context</title>
		<link>http://www.digizenstudio.com/blog/2007/01/14/programmatically-build-a-spring-application-context/</link>
		<comments>http://www.digizenstudio.com/blog/2007/01/14/programmatically-build-a-spring-application-context/#comments</comments>
		<pubDate>Sun, 14 Jan 2007 19:56:55 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/2007/01/14/programmatically-build-a-spring-application-context/</guid>
		<description><![CDATA[The new BeanDefinitionBuilder class added in Spring 2.0 allows an XML-less way to build application contexts programmatically. Can be very useful for, say, creating quick testing setups in one of those script languages.]]></description>
			<content:encoded><![CDATA[<p>The new <a href="http://static.springframework.org/spring/docs/2.0.x/api/org/springframework/beans/factory/support/BeanDefinitionBuilder.html" rel="_blank">BeanDefinitionBuilder</a> class added in Spring 2.0 allows an XML-less way to build application contexts programmatically. Can be very useful for, say, creating quick testing setups in one of those script languages.<span id="more-126"></span></p>
<div class="igBar"><span id="ljava-5"><a href="#" onclick="javascript:showPlainTxt('java-5'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div id="java-5">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">GenericApplicationContext ctx = <span style="color: #000000; font-weight: bold;">new</span> GenericApplicationContext<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">BeanDefinitionBuilder builderA = BeanDefinitionBuilder</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; .<span style="color: #006600;">rootBeanDefinition</span><span style="color: #66cc66;">&#40;</span>BeanA.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; .<span style="color: #006600;">addPropertyValue</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"name"</span>, <span style="color: #ff0000;">"Joe"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ctx.<span style="color: #006600;">registerBeanDefinition</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"bean-a"</span>, builderA.<span style="color: #006600;">getBeanDefinition</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">BeanDefinitionBuilder builderB = BeanDefinitionBuilder.<span style="color: #006600;">rootBeanDefinition</span><span style="color: #66cc66;">&#40;</span>BeanB.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #66cc66;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; .<span style="color: #006600;">addPropertyReference</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"refA"</span>, <span style="color: #ff0000;">"bean-a"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ctx.<span style="color: #006600;">registerBeanDefinition</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"bean-b"</span>, builderB.<span style="color: #006600;">getBeanDefinition</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">ctx.<span style="color: #006600;">getBean</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"bean-b"</span><span style="color: #66cc66;">&#41;</span>; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>The sample code above creates two bean definitions, the second one referencing the first.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2007/01/14/programmatically-build-a-spring-application-context/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Spring Controllers with Prototype Scope</title>
		<link>http://www.digizenstudio.com/blog/2006/10/09/spring-controllers-with-prototype-scope/</link>
		<comments>http://www.digizenstudio.com/blog/2006/10/09/spring-controllers-with-prototype-scope/#comments</comments>
		<pubDate>Tue, 10 Oct 2006 01:44:34 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/2006/10/09/spring-controllers-with-prototype-scope/</guid>
		<description><![CDATA[Most of the time, we configure the controllers in our Spring MVC application to be singletons, because of the their stateless nature. However, being configured as normal Spring beans, Spring controllers can also be declared with the prototype scope. Sometimes, it can actually be quite a useful feature. For instance, in a controller that descends [...]]]></description>
			<content:encoded><![CDATA[<p>Most of the time, we configure the controllers in our Spring MVC application to be singletons, because of the their stateless nature. However, being configured as normal Spring beans, Spring controllers can also be declared with the prototype scope.<span id="more-113"></span> Sometimes, it can actually be quite a useful feature. For instance, in a controller that descends from SimpleFormController, let's say the formBackingObject() method needs to load an object from the DB that is necessary to instantiate the actual form object, and that same object also will also be used during onSubmit and/or referenceData(). Otherthan either reloading the object later, or resorting to storing the object in the request or even the session, a more convenient, less prone to name space clashing, and arguably more OO approach would be making it an instance variable, and making the controller a prototype bean.</p>
<p>Unlike a singleton controller, a prototype scope controller must have its bean name added to the 'mappings' property of the SimpleUrlHandlerMapping bean, instead of the 'urlMap' property, which requires an actual bean reference. The small price here is that, since the bean name is textually added to the mapping, there won't be any XML validation against it. (In fact, I don't think Spring IDE would catch an invalid bean name here either.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2006/10/09/spring-controllers-with-prototype-scope/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A Spring Singleton is not a Singleton</title>
		<link>http://www.digizenstudio.com/blog/2006/09/14/a-spring-singleton-is-not-a-singleton/</link>
		<comments>http://www.digizenstudio.com/blog/2006/09/14/a-spring-singleton-is-not-a-singleton/#comments</comments>
		<pubDate>Fri, 15 Sep 2006 03:03:00 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/2006/09/14/a-spring-singleton-is-not-a-singleton/</guid>
		<description><![CDATA[OK, I know this sounds like another one of those "a white horse is not a horse" arguments, but from my observation on the Spring forums and other blog reading, some clear distinction between the semantics of a Spring singleton and a classical Java singleton has become much necessary. The overloaded term has caused quite [...]]]></description>
			<content:encoded><![CDATA[<p>OK, I know this sounds like another one of those "a white horse is not a horse" arguments, but from my observation on the Spring forums and other blog reading, some clear distinction between the semantics of a Spring singleton and a classical Java singleton has become much necessary. The overloaded term has caused quite some confusion, especially for someone who has just started picking up Spring.<span id="more-112"></span></p>
<p>First let's examine how a bean is made a singleton in Spring:</p>
<div class="igBar"><span id="lxml-8"><a href="#" onclick="javascript:showPlainTxt('xml-8'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-8">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"foo"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"Foo"</span> <span style="color: #000066;">singleton</span>=<span style="color: #ff0000;">"true"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>What the 'singleton' attribute really makes Spring do is to cache and always return the same bean instance for all the requests on this bean. As far as the comparison to a classical Java singleton is concerned, there are two distinctions that need to be noted here:</p>
<p>1. The caching of a bean instance happens only within a single Spring <code>ApplicationContext</code> instance - referred to as the "Spring IoC container" in Spring documentation. So obviously if I have another bean defined with the same id and the same class in a separate <code>ApplicationContext</code> instance, that one would be a completely different one. (Note that here we are talking about <code>ApplicationContext</code> instances, not context definition XML files, because more than one file can be loaded into one context instance. As far as the singleton scope is concerned, it is the instance not the files that counts.) In contrast, if we look at a Java singleton, its scope of singularity applies to the "universe" managed by the classloader that loaded this class.</p>
<p>2. When a bean reference is requested from an application context, the id or the name is used to identify the bean wanted. On the other hand, when we call <code>Bar.getInstance()</code>, we are really using the class <code>Bar</code> to identify what we instend to receive. If that didn't sound like something significant, consider a scenario where two beans of the same class are defined in the same <code>ApplicationContext</code>:</p>
<div class="igBar"><span id="lxml-9"><a href="#" onclick="javascript:showPlainTxt('xml-9'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-9">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"foo1"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"Foo"</span> <span style="color: #000066;">singleton</span>=<span style="color: #ff0000;">"true"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"foo2"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"Foo"</span> <span style="color: #000066;">singleton</span>=<span style="color: #ff0000;">"true"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
There will be two bean instances created in this context, both of type <code>Foo</code>, but one under id 'foo1', another under id 'foo2'. Clearly that's behavior we'd never see in Java singletons.</p>
<p>Having noted the two distinctions above, it becomes clear that a Spring singleton has some semantics rather orthogonal to those of a Java singleton - "orthogonal" in the sense that neither is the singularity of a Spring singleton meaningful in any scope definition based on classloaders, nor is a Spring singleton instance associated to any specific class. On the other hand, as we all would recognize, those are the two fundamental characteristics of a Java singleton.</p>
<p>Hopefully, this confusion will be clarified to some extent in Spring 2.0, with the newly introduced 'scope' attribute and the session, request, and global session scopes. Also Section 3.4 Bean Scope in the Spring 2.0 Reference explicitly puts out a warning note on the difference between the Spring singleton scope and the classical Singleton Pattern. Although I still think that it could have had the issue completely addressed, had the scope value "singleton" been renamed to something like "container" altogether - but then, I can also see some new confusion arising from that, like "how is this supposed to map to the singleton thing from before?"</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2006/09/14/a-spring-singleton-is-not-a-singleton/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Inject Spring Beans into JSP Tags</title>
		<link>http://www.digizenstudio.com/blog/2006/05/07/inject-spring-beans-into-jsp-tags/</link>
		<comments>http://www.digizenstudio.com/blog/2006/05/07/inject-spring-beans-into-jsp-tags/#comments</comments>
		<pubDate>Mon, 08 May 2006 03:46:02 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[aop]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/?p=96</guid>
		<description><![CDATA[Spring 2.0 supports injecting beans into an arbitrary POJO, which isn't necessarily instantiated by a Spring bean factory. This powerful feature is mostly used in injecting into domain objects whose life cycle is usually managed by ORM tools such as Hibernate. But we don't have to stop here, e.g., JSP tags can also be injected [...]]]></description>
			<content:encoded><![CDATA[<p>Spring 2.0 supports injecting beans into an arbitrary POJO, which isn't necessarily instantiated by a Spring bean factory. This powerful feature is mostly used in injecting into domain objects whose life cycle is usually managed by ORM tools such as Hibernate. But we don't have to stop here, e.g., JSP tags can also be injected the same way. Here's how:<span id="more-96"></span></p>
<p>First let's have a sample tag implementation:</p>
<div class="igBar"><span id="ljava-12"><a href="#" onclick="javascript:showPlainTxt('java-12'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div id="java-12">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// In order for itself to be picked up by</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// Spring for injection, a class needs to wear</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">// this @Configurable &quot;badge&quot;...</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">@Configurable</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> InjectedTag <span style="color: #000000; font-weight: bold;">extends</span> SimpleTagSupport <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> AService _service;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">/***/</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; @Override</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> doTag<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> <a href="http://www.google.com/search?q=allinurl%3AIOException+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">IOException</span></a> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; getJspContext<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getOut</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">write</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Service injected: "</span> + _service + <span style="color: #ff0000;">"&lt;br /&gt;"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setService<span style="color: #66cc66;">&#40;</span>AService service<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; _service = service;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Now, in the Spring application context file:</p>
<div class="igBar"><span id="lcode-13"><a href="#" onclick="javascript:showPlainTxt('code-13'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-13">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;aop :spring-configured/&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;bean id=<span style="color:#CC0000;">"aService"</span> class=<span style="color:#CC0000;">"com.foo.AService"</span>&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &lt;!-- configure the service. --&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/bean&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;bean class=<span style="color:#CC0000;">"com.foo.InjectedTag"</span> lazy-init=<span style="color:#CC0000;">"true"</span>&gt;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &lt;property name=<span style="color:#CC0000;">"service"</span>&gt;&lt;ref local=<span style="color:#CC0000;">"aService"</span>/&gt;&lt;/property&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&lt;/bean&gt; </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>That's all there is to it.  The tag declaration in the TLD isn't really relevant, because it's no different from what you would do with any other tags, but for the sake of completeness...-<br />
<code><br />
&lt;tag&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;name&gt;injectedTag&lt;/name&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;tag-class&gt;com.foo.InjectedTag&lt;/tag-class&gt;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&lt;body-content&gt;empty&lt;/body-content&gt;<br />
&lt;/tag&gt;<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2006/05/07/inject-spring-beans-into-jsp-tags/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>The Circular Bean Reference Problem in Spring 2.0&#8217;s Arbitrary Domain Object Wiring</title>
		<link>http://www.digizenstudio.com/blog/2006/02/06/the-circular-bean-reference-problem-in-spring-20s-arbitrary-domain-object-wiring/</link>
		<comments>http://www.digizenstudio.com/blog/2006/02/06/the-circular-bean-reference-problem-in-spring-20s-arbitrary-domain-object-wiring/#comments</comments>
		<pubDate>Tue, 07 Feb 2006 03:00:22 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[aop]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/?p=86</guid>
		<description><![CDATA[Spring 2.0 has an exciting new feature that, with AspectJ's powerful AOP support, allows arbitrary domain objects to be injected with dependencies at the time of creation, even when the domain object is not created by Spring. This feature helps developers avoiding the "Anemic Domain Model" because now domain objects can have references to services [...]]]></description>
			<content:encoded><![CDATA[<p>Spring 2.0 has an exciting new feature that, with AspectJ's powerful AOP support, allows arbitrary domain objects to be injected with dependencies at the time of creation, even when the domain object is not created by Spring. This feature helps developers avoiding the "Anemic Domain Model" because now domain objects can have references to services or even DAO's, instead of just some other domain objects.<span id="more-86"></span></p>
<p>This particular problem comes when I try to inject a DAO into a domain object (I know it's some debatable practice, but please just bear me for a moment).  So the DO is annotated with @Configurable, its constructor is advised such that, at runtime, after the initialization, the Spring aspect will try to get a reference to the DAO, and sets it into this new DO instance. However, in order to materialize the DAO, which naturally holds a reference to a Hibernate session factory. The session factory needs to be instantiated  first - and that, surprisingly, is when I get the "circular bean reference" meltdown.</p>
<p>After one pint of log reading, three shots of source code tracing, and a pinch of hair pulling, this here turns out to be the story: at the session factory initialization time, Hibernate3 needs to know which id value represents an unsaved object. E.g., null, -1, or whatever sensible value depending on the nature of the object and the corresponding table. This value is specified via the 'unsaved-value' attribute in the object mapping., and, as suggested by the reference, can usually be omitted safely, for Hibernate3 is very smart and can actually guess the unsaved-value by instantiating a new instance of the DO, which naturally would be intercepted by Spring and be injected with a DAO reference, which naturally would need a reference to the session factory, which naturally would have to guess what the unsaved-value is....</p>
<p>The solution is easy - just add 'unsaved-value="null"' to the mapping file, to prevent Hibernate from attemping the guess.</p>
<p>Now, I can hear you making some impatient noise - "what's all this inject-DAO-into-DO business?!"  Well, I agree it's some debatable practice, but then it's also hardly the point here.  I could well have tried to inject a service object into this DO, and the service object could have held a legit reference to some DAO. It would have been the same circular reference, only a larger circle.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2006/02/06/the-circular-bean-reference-problem-in-spring-20s-arbitrary-domain-object-wiring/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>I Don&#8217;t Get &#8220;I Don&#8217;t Get Spring&#8221;</title>
		<link>http://www.digizenstudio.com/blog/2006/01/30/i-dont-get-i-dont-get-spring/</link>
		<comments>http://www.digizenstudio.com/blog/2006/01/30/i-dont-get-i-dont-get-spring/#comments</comments>
		<pubDate>Tue, 31 Jan 2006 01:05:42 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/?p=84</guid>
		<description><![CDATA[I was reading Bob Lee's Spring bashing blog entry, and, while realizing how high the flaming index the article carries, being a long-time Spring advocate, felt that I had to respond.
Oh, and let me get this out of the way first, too - I mean no offense to Bob (I'm sure he is a good [...]]]></description>
			<content:encoded><![CDATA[<p>I was reading <a href="http://crazybob.org/2006/01/i-dont-get-spring.html" rel="_blank">Bob Lee's Spring bashing blog entry</a>, and, while realizing how high the flaming index the article carries, being a long-time Spring advocate, felt that I had to respond.<span id="more-84"></span></p>
<p>Oh, and let me get this out of the way first, too - I mean no offense to Bob (I'm sure he is a good person). <img src='http://www.digizenstudio.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Bob starts with:</p>
<blockquote><p>... but frankly I haven't been able to get my head around your framework. Even worse, I've noticed what I consider to be a dangerous and blind increase in the rate of Spring adoption. I've yet to read a critical article or book on Spring.</p></blockquote>
<p>Well, what <em>I</em> don't get is, how can one "get one's head around" anything, if one doesn't even bother to read on it first?</p>
<blockquote><p>... Maybe Spring adoption is a knee-jerk reaction to J2EE. "J2EE is bad, and the Spring guys say their stuff is better, so Spring must be good." It doesn't work that way.</p></blockquote>
<p>Maybe, but then maybe not.</p>
<p>Firstly, even though I can't speak for the Spring Team, I don't think Spring is targeted to replace J2EE.  If Bob wouldn't mind just taking a peek at the Spring forums, he most certainly would realize most questions asked there are about how to leverage Spring in a <em>J2EE</em> application.</p>
<p>Secondly, last time I checked, the Spring team and most of the Spring users live in a society where information flows freely, and in an industry where competition is hot.  Rod Johnson et. al. can't just hypnotize people into thinking Spring is good.  So, it's not like "The US is bad, and Kim Jung Il says he is better, so he must be good." No, sir, it doesn't work <em>that</em> way.</p>
<blockquote><p>The Spring folks openly snub their noses at J2EE, but from what I can tell Spring isn't exactly lightweight and simple either. </p></blockquote>
<p>Would Bob mind giving a link to the above "nose snubbing?"  As far as I know, the furthest Rod Johnson has gone so far is a book by him on "J2EE without EJB".  Can we agree that J2EE &#8800; EJB?</p>
<blockquote><p>The Javadocs are unnecessarily overwhelming. Does all of this really belong in a user API? At least J2EE cleanly separates API from implementation. </p></blockquote>
<p>That's because J2EE <em>is</em> an API, and doesn't <em>have</em> any implementation to begin with.  And I personally find Spring's javadoc the best among the OSS projects I've ever worked with, and better than lots of commercial packages, too.  Most of the javadoc does talk about the API from the user perspective - what the API does, what the usual usage patterns are, what the best practice would be, etc.  Seldomly it gets a bit longwinding, but I for one am willing to live with that, rather than opening up the class description for DefaultDAOImpl and finding myself staring at "The default implementation of the DAO."</p>
<blockquote><p>Spring advocates tout that Spring doesn't "touch" your code, i.e. you don't have to implement any Spring-specific interfaces (with the exception of life-cycle interfaces, etc.). News flash: the XML configuration is my code, and from what I can see it often ends up constituting a lot of code, all of which is Spring-specific.</p></blockquote>
<p>Valid point.  The XML is indeed Spring-specific.  But that doesn't necessarily make the container agnostic on the Java code side meaningless.  Following the same logic, the J2EE "standard" would be a phony, too, because when was the last time you deployed a serious enterprise application without having to supply files like weblogic-ejb.xml, or jboss.xml?</p>
<blockquote><p>Back to dependencies on Spring APIs; don't I have to call the container to create my first object (assuming the rest of the Spring-managed objects in the graph are injected)? I want some way to check that the object I'm requesting is the right type at compile time. I don't want to cast. Ever.</p></blockquote>
<p>Another valid point, albeit not very constructive - since Bob already admitted earlier that:</p>
<blockquote><p>... I'm talking about Spring specifically, not dependency injection. I love dependency injection, and I follow the patterns every day. Good riddance to service locators!</p></blockquote>
<p>Why don't we ask Bob to tell us how to implement configurable DI without any casting?  Also, I'd like to remind Bob that the same argument applies to all the reflection usage as well.  Does Bob never use reflection, ever?</p>
<blockquote><p>It bothers me that I have to reference Spring implementation classes in my XML configuration. I don't care about the plumbing. In Spring's defense, I've heard they have so more concise, domain-specific XML coming in 2.0, but I haven't seen it yet. Why didn't this come up sooner?</p></blockquote>
<p>Nobody <em>has to</em> reference Spring implementation classes in the bean definitions.  They are just implementations that are convenient to use.  Feel free to write your own and plug them in.</p>
<p>And, yeah, sure, why didn't &lt;plug in your dream feature here&gt; come up sooner?</p>
<blockquote><p>What's with auto-wiring? Does anyone actually use that, or is just another notch in the feature headboard?</p></blockquote>
<p>I don't use auto-wiring in production code, because I think it's too automagic, but, from what I can tell on the forums, a lot of users don't mind.  And one very popular use of auto-wiring is in writing test cases.  It helps easing a lot of pain from having to wiring up the dependencies explicitly.</p>
<blockquote><p>Fortunately, simply adopting dependency injection design patterns gets you 90% of the way, further if you don't need encouragement to do the right thing.</p></blockquote>
<p>I wonder how Bob would implement meaningful (i.e. configurable) DI without making it another container that has all "these same problems."  Show us how you would go that "90% of the way", would you, Bob?  <img src='http://www.digizenstudio.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2006/01/30/i-dont-get-i-dont-get-spring/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t Forget To Describe Your constructor-arg</title>
		<link>http://www.digizenstudio.com/blog/2006/01/20/dont-forget-to-describe-your-constructor-arg/</link>
		<comments>http://www.digizenstudio.com/blog/2006/01/20/dont-forget-to-describe-your-constructor-arg/#comments</comments>
		<pubDate>Sat, 21 Jan 2006 03:47:34 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/?p=79</guid>
		<description><![CDATA[One often overlooked feature in Spring bean definitions is the ability to add a &#60;description&#62; element to almost everything: beans, properties, or constructor arguments.   It makes a lot of sense especially in the case of &#60;constructor-arg&#62;, because usually setting a bean property is fairly obvious:
PLAIN TEXT
XML:




&#60;property name="timeInterval" value="100"/&#62; 






But not so when the [...]]]></description>
			<content:encoded><![CDATA[<p>One often overlooked feature in Spring bean definitions is the ability to add a &lt;description&gt; element to almost everything: beans, properties, or constructor arguments.   It makes a lot of sense especially in the case of &lt;constructor-arg&gt;, because usually setting a bean property is fairly obvious:<span id="more-79"></span></p>
<div class="igBar"><span id="lxml-17"><a href="#" onclick="javascript:showPlainTxt('xml-17'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-17">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"timeInterval"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"100"</span><span style="font-weight: bold; color: black;">/&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
But not so when the above is done in a &lt;constructor-arg&gt;.  Constructor arguments are not looked up by name, but by index or type:</p>
<div class="igBar"><span id="lxml-18"><a href="#" onclick="javascript:showPlainTxt('xml-18'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-18">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;constructor</span> -arg <span style="color: #000066;">index</span>=<span style="color: #ff0000;">"0"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"100"</span><span style="font-weight: bold; color: black;">/&gt;</span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
Instead, this would make it a lot clearer:</p>
<div class="igBar"><span id="lxml-19"><a href="#" onclick="javascript:showPlainTxt('xml-19'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-19">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;constructor</span> -arg <span style="color: #000066;">index</span>=<span style="color: #ff0000;">"0"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"100"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;description<span style="font-weight: bold; color: black;">&gt;</span></span></span>For the time interval. In milliseconds.<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/description<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/constructor<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>My only wish is for the Spring team to consider adding a 'description' attribute.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2006/01/20/dont-forget-to-describe-your-constructor-arg/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Call Me Pedantic &#8211; What Exactly IS Scalability?</title>
		<link>http://www.digizenstudio.com/blog/2006/01/16/what-exactly-is-scalability/</link>
		<comments>http://www.digizenstudio.com/blog/2006/01/16/what-exactly-is-scalability/#comments</comments>
		<pubDate>Mon, 16 Jan 2006 18:36:42 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[fisheye]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/?p=75</guid>
		<description><![CDATA[This is mostly triggered by Diego Parrilla's post Spring is not designed for scalability, in which he goes, "...Basically you have two options if you want to scale with pure web applications...", and then gives two options to scale, both of which involves state replicating clustering schemes.  There, Diego, you got on my pedantic [...]]]></description>
			<content:encoded><![CDATA[<p>This is mostly triggered by Diego Parrilla's post <a href="http://www.diegoparrilla.com/2006/01/spring-is-not-designed-for-scalability.html" rel="_blank">Spring is not designed for scalability</a>, in which he goes, "...Basically you have two options if you want to scale with pure web applications...", and then gives two options to scale, both of which involves state replicating clustering schemes.  There, Diego, you got on my pedantic nerve. <img src='http://www.digizenstudio.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   I can't help but wondering this question - what, exactly is Scalability?<span id="more-75"></span></p>
<p>So I went on and did a bit research (OK, OK, I really just googled "define: Scalability"), and got  <a href="http://www.google.com/search?num=20&#038;hl=en&#038;hs=NXC&#038;lr=&#038;c2coff=1&#038;client=firefox-a&#038;rls=org.mozilla:en-US:official&#038;oi=defmore&#038;defl=en&#038;q=define:Scalability" rel="_blank">these definitions</a>. Let me just quote the first three here:</p>
<blockquote><p>The ability to scale to support larger or smaller volumes of data and more or less users. The ability to increase or decrease size or capability in cost-effective increments with minimal impact on the unit cost of business and the procurement of additional services. - dmreview.com</p></blockquote>
<blockquote><p>The ability and flexibility of an application to meet growth requirements of an organization. - hostqueue.com</p></blockquote>
<blockquote><p>The ability to expand a computing solution to support large numbers of users without impacting performance. - primode.com</p></blockquote>
<p>So scalability is about performance - the capability to handle large volume of traffic, as far as web applications go.  It does not have anything to do with "miminal service interruption when one of the servers goes down" - that's <a href="http://www.ieeetfcc.org/high-availability.html" rel="_blank">High Availability</a>.  It especially does not have anything to do with "<em>no</em> service interruption whatsoever" - that's Continuous Availability (see the last link). We usually don't need the expensive state-replicating schemes to achieve Scalability, or even High Availability.  A sticky-session load balancer and a server farm without busily replicating sessions among themselves would scale well, and would provide some pretty high availability.  It can't provide Continuous Availability because when a server fails all the users on that server at that point would have lost their sessions.  That's the only case where clustering comes in and support immediate fail-over without any interruption to the service.</p>
<p>Now, the real question for all you architects out there that can't wait to hop on the "clustering wagon" the second you hear "scalability" is, is your application really "mission-critical" enough, meaning no user can ever lose her session, to justify the cost to implementing clustering?  Remember the cost here includes not only the performance penalty (ironic isn't it), but also the development penalties - you'll have to make sure that whatever you stick in the session implements the Serializable interface, that whatever you stick in there references does the same, and finally that not too much is stuck in there.</p>
<p>On a separate level, I don't necessarily agree with Diego's comment (his main point actually) on Spring being not scalable, either.   The fallacy here, IMHO, is the same as what I have seen from a lot of other online discussions.  It's that people keep trying to compare Spring with EJB, forgetting they are different things and meant for different things.</p>
<p>What is Spring?  Even though we all refer to Spring as a <em>container</em>, we have to remember that it's a completely different kind of container from the kind EJB is.  Spring is a <em>bean container</em>, or rather more accurately, as the name of one of its core interfaces shows, it is a <em>bean factory</em>.  All Spring does is providing us the ability to transparently wire up our applications, and the convenience to easily integrate with lots of third-part tools, but Spring does not reinvent the wheels by reimplementing those tools on itself.  E.g., Spring provides easy integration with well-known ORM tools such as Hibernate and iBatis, rather than providing it own ORM package.  On the other hand, EJB is a <em>container</em> in the real sense of "All Your Base Are Belong To Us" <img src='http://www.digizenstudio.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .  It provides a complete solution with a more restrictive programming paradiam.  Spring is not mutually exclusive with EJB, nor is it a competitor of the latter one.  You can use Spring to wire up an EJB-based service layer just as easy as you do, say, a Hessian-based one.  Comparing Spring to EJB is like comparing apple and orange.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2006/01/16/what-exactly-is-scalability/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Clean Desk, Messy Drawer</title>
		<link>http://www.digizenstudio.com/blog/2005/10/17/clean-desk-messy-drawer/</link>
		<comments>http://www.digizenstudio.com/blog/2005/10/17/clean-desk-messy-drawer/#comments</comments>
		<pubDate>Tue, 18 Oct 2005 02:40:14 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/?p=73</guid>
		<description><![CDATA[My wife, despite all of her loveliness, does have her own ways of annoying me from time to time, one of which being how she cleans up our office desks - she would sweep everything off the surface of the desk and into the two top drawers, shut them close, and claim "Ta-da! See how [...]]]></description>
			<content:encoded><![CDATA[<p>My wife, despite all of her loveliness, does have her own ways of annoying me from time to time, one of which being how she cleans up our office desks - she would sweep everything off the surface of the desk and into the two top drawers, shut them close, and claim "Ta-da! See how neat it looks <em>now</em>!"<span id="more-73"></span></p>
<p>Sadly, in the recent years, I have been observing more and more of this "let's move things around and call it clean" approach being applied in the software development community.  What finally triggered me to put down my rant in this blog is the <a href="http://jroller.com/page/habuma?entry=spring_simplified_with_xbean" rel="_blank">Spring Simplified with XBean</a> proposed by Craig Walls recently.</p>
<p>I was, in face, perfectly OK with the first part of the article: Spring context files tend to be verbose - hear, hear; We could use autowire and XML name space to simplify it a bit - sure, k:HolyGrailQuest is definitely more intuitive than the FQN of the same class, I can buy that, even forgetting the price of enduring some extra API dependence on XBean for a moment.</p>
<p>And then there it came "the drawer", in this case being a property file:</p>
<blockquote><p>
...<br />
In the example above, the XML namespace was a "java://" URI and XBean assumed some simple conventions for the XML tags and attributes. But if the namespace is an "http://" URI, it can be used to lookup a properties file that guides XBean to alias class names and property names into custom XML tags and attributes.<br />
...
</p></blockquote>
<p>After applying the property file (and in any real application I wouldn't be surprised if there ends up being a number of them scattered all over the classpath), the original Spring context file is reduced, not only in terms of size, _but also_ in terms of the information it conveys.  Granted, with all the verbosity in the original context file, it would take me a while to get a hold of how the beans are configured, but at least I still could. And the verbosity would become much lesser of an obstacle after the initial learning curve.  Now with all the actual class names being externalized (again) into a separate property file, I can stare at the context file for all day and still have no idea as to which concrete class a bean definition will be instantiated with.</p>
<p>Towards the end of the blog, Craig gives a before/after comparison of the two Spring context files that shows the "simplification" cuts the size of the file to half.  My argument, however, would be that a true comparison should be between the original file and the simplified one <em>plus</em> the property file.</p>
<p>And even that would be ignoring some hidden cost introduced - it's always harder and hence less productive to reference back and forth between files than to work within a single one.  In this particular case, I don't really think the cost is justified.  while Spring context files are indeed verbose, and _can_ become a real mess if you are not careful, somehow it has never become a problem for me in any practical sense -- maybe thanks to Spring's own ability to load and merge multiple context files into one definition, its ability to import context files into one master, and the Eclipse plugins I have picked up such as <a href="http://www.springide.org" rel="_blank">Spring IDE</a> and <a href="http://xmlbuddy.com/" rel="_blank">XML Buddy</a>.</p>
<p>Of course, as I said in the beginning, this rant of mine didn't just come from this one incident.  People are trying to clean up the desk by sweeping the mess into drawers on much larger scales.  For instance, initially we didn't feel like hardcoding Web application control flows, URL bindings, and all other sort of volatile mass into Java code, so we came up with various formats of XML files to dump those things into. Then annotation came along, so we somehow felt it would be cool to move those things back into Java code, only in the "meta data section" this time. And then some other folks developed tools that "allows you to externalize the annotations into XML or property-based configuration files."</p>
<p>Back to Craig's idea on simplifying Spring, I would like to conclude this article by a one-dollar wager - as soon as there are enough folks going along with this approach, I bet some of us will go ahead and develop "an extension to XBean that supports specifying Spring bean aliases and class names in XML files instead of the rather limited properties format."  Now, any of you care to take me up on this one?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2005/10/17/clean-desk-messy-drawer/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Deploy Spring Sample to Liferay 3.6.1/Tomcat</title>
		<link>http://www.digizenstudio.com/blog/2005/08/31/liferay361-tomcat-spring/</link>
		<comments>http://www.digizenstudio.com/blog/2005/08/31/liferay361-tomcat-spring/#comments</comments>
		<pubDate>Thu, 01 Sep 2005 02:06:10 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/?p=68</guid>
		<description><![CDATA[Just upgraded to Liferay Pro 3.6.1 (Tomcat 5.5.9).  Smooth process as usual with just a couple minor points make a note of.
A couple folks seem to have some problem getting the Spring Portlet sample portlet content rendered. I just gave it a try and it appears to work fine with my installation. I guess [...]]]></description>
			<content:encoded><![CDATA[<p>Just upgraded to Liferay Pro 3.6.1 (Tomcat 5.5.9).  Smooth process as usual with just a couple minor points make a note of.<span id="more-68"></span></p>
<p>A couple folks seem to have some problem <a href="/blog/2005/07/27/hotdeploy-into-liferay350/#comments">getting the Spring Portlet sample portlet content rendered</a>. I just gave it a try and it appears to work fine with my installation. I guess you need to use Liferay's hot deploy script, and follow the steps listed in the <a href="http://www.liferay.com/web/guest/documentation/development/hot_deploy#2" rel="_blank">Development guide</a>. Copying the portlet directory into tomcat's webapps directory won't work because Liferay won't get a chance to do its own magic - like, make a little "adjustment" to your web.xml. <img src='http://www.digizenstudio.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>And here goes the latest version of the deployer script I used, in case you need it:</p>
<div class="igBar"><span id="lxml-22"><a href="#" onclick="javascript:showPlainTxt('xml-22'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-22">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;project</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"portlet-deployer"</span> <span style="color: #000066;">basedir</span>=<span style="color: #ff0000;">"."</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">"deploy"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"init"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">environment</span>=<span style="color: #ff0000;">"env"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Tomcat --&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"app.server.type"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"tomcat"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"app.server.dir"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"e:\tomcats\5.5.9-liferay"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"app.server.deploy.dir"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"${app.server.dir}/webapps"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;path</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"project.classpath"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;pathelement</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">"${env.ANT_HOME}/lib/ant.jar"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">"${app.server.dir}/shared/lib"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;pathelement</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">"${app.server.dir}/common/lib/servlet-api.jar"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/path<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/target<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"deploy"</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">"init"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;java</span> <span style="color: #000066;">classname</span>=<span style="color: #ff0000;">"com.liferay.portal.tools.PortletDeployer"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">classpathref</span>=<span style="color: #ff0000;">"project.classpath"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">fork</span>=<span style="color: #ff0000;">"true"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066;">newenvironment</span>=<span style="color: #ff0000;">"true"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Required Arguments --&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;jvmarg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"-Ddeployer.base.dir=./"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;jvmarg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"-Ddeployer.dest.dir=${app.server.deploy.dir}"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;jvmarg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"-Ddeployer.app.server.type=${app.server.type}"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;jvmarg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"-Ddeployer.portlet.taglib.dtd=${liferay.dir}/WEB-INF/tld/liferay-portlet.tld"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Optional Arguments --&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;jvmarg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"-Ddeployer.jboss.prefix=1"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;jvmarg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"-Ddeployer.tomcat.lib.dir=${app.server.dir}/shared/lib"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Dependent Libraries --&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"${app.server.deploy.dir}/ext.ear/portal-web-complete.war/WEB-INF/lib/util-taglib.jar"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"${app.server.deploy.dir}/ext.ear/lib/util-java.jar"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!--&lt;arg value=&quot;${app.server.deploy.dir}/ext.ear/lib/util-jsf.jar&quot; /&gt;</span></span>--&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/java<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/target<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/project<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>Here's one note to myself in the future - if you get something like this while running the hot deployer script:</p>
<div class="igBar"><span id="lcode-23"><a href="#" onclick="javascript:showPlainTxt('code-23'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">CODE:</span>
<div id="code-23">
<div class="code">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color:#006600; font-weight:bold;">&#91;</span>java<span style="color:#006600; font-weight:bold;">&#93;</span> Deploying spring-portlet-sample.<span style="">war</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#91;</span>java<span style="color:#006600; font-weight:bold;">&#93;</span>&nbsp; &nbsp;Expanding: .\spring-portlet-sample.<span style="">war</span> into <span style="color:#800000;color:#800000;">20050831212239171</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#91;</span>java<span style="color:#006600; font-weight:bold;">&#93;</span>&nbsp; &nbsp;Modifying <span style="color:#800000;color:#800000;">20050831212239171</span>\WEB-INF\web.<span style="">xml</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#91;</span>java<span style="color:#006600; font-weight:bold;">&#93;</span> java.<span style="">lang</span>.<span style="">NullPointerException</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#91;</span>java<span style="color:#006600; font-weight:bold;">&#93;</span>&nbsp; &nbsp; &nbsp;at com.<span style="">liferay</span>.<span style="">util</span>.<span style="">FileUtil</span>.<span style="">listFiles</span><span style="color:#006600; font-weight:bold;">&#40;</span>FileUtil.<span style="">java</span>:<span style="color:#800000;color:#800000;">245</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#91;</span>java<span style="color:#006600; font-weight:bold;">&#93;</span>&nbsp; &nbsp; &nbsp;at com.<span style="">liferay</span>.<span style="">util</span>.<span style="">FileUtil</span>.<span style="">listFiles</span><span style="color:#006600; font-weight:bold;">&#40;</span>FileUtil.<span style="">java</span>:<span style="color:#800000;color:#800000;">237</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#91;</span>java<span style="color:#006600; font-weight:bold;">&#93;</span>&nbsp; &nbsp; &nbsp;at com.<span style="">liferay</span>.<span style="">portal</span>.<span style="">tools</span>.<span style="">BaseDeployer</span>.<span style="">deployDirectory</span><span style="color:#006600; font-weight:bold;">&#40;</span>BaseDeployer.<span style="">java</span>:<span style="color:#800000;color:#800000;">229</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#91;</span>java<span style="color:#006600; font-weight:bold;">&#93;</span>&nbsp; &nbsp; &nbsp;at com.<span style="">liferay</span>.<span style="">portal</span>.<span style="">tools</span>.<span style="">BaseDeployer</span>.<span style="">deployFile</span><span style="color:#006600; font-weight:bold;">&#40;</span>BaseDeployer.<span style="">java</span>:<span style="color:#800000;color:#800000;">272</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#91;</span>java<span style="color:#006600; font-weight:bold;">&#93;</span>&nbsp; &nbsp; &nbsp;at com.<span style="">liferay</span>.<span style="">portal</span>.<span style="">tools</span>.<span style="">BaseDeployer</span>.<span style="">deploy</span><span style="color:#006600; font-weight:bold;">&#40;</span>BaseDeployer.<span style="">java</span>:<span style="color:#800000;color:#800000;">188</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#91;</span>java<span style="color:#006600; font-weight:bold;">&#93;</span>&nbsp; &nbsp; &nbsp;at com.<span style="">liferay</span>.<span style="">portal</span>.<span style="">tools</span>.<span style="">BaseDeployer</span>.&lt;init&gt;<span style="color:#006600; font-weight:bold;">&#40;</span>BaseDeployer.<span style="">java</span>:<span style="color:#800000;color:#800000;">81</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#91;</span>java<span style="color:#006600; font-weight:bold;">&#93;</span>&nbsp; &nbsp; &nbsp;at com.<span style="">liferay</span>.<span style="">portal</span>.<span style="">tools</span>.<span style="">PortletDeployer</span>.&lt;/init&gt;&lt;init&gt;<span style="color:#006600; font-weight:bold;">&#40;</span>PortletDeployer.<span style="">java</span>:<span style="color:#800000;color:#800000;">71</span><span style="color:#006600; font-weight:bold;">&#41;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color:#006600; font-weight:bold;">&#91;</span>java<span style="color:#006600; font-weight:bold;">&#93;</span>&nbsp; &nbsp; &nbsp;at com.<span style="">liferay</span>.<span style="">portal</span>.<span style="">tools</span>.<span style="">PortletDeployer</span>.<span style="">main</span><span style="color:#006600; font-weight:bold;">&#40;</span>PortletDeployer.<span style="">java</span>:<span style="color:#800000;color:#800000;">63</span><span style="color:#006600; font-weight:bold;">&#41;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
It's because the tomcat lib directory set in the script doesn't exist.</init></p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2005/08/31/liferay361-tomcat-spring/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Liferay Pro 3.5.0, Tomcat 5.5, and Spring Portlet Sample</title>
		<link>http://www.digizenstudio.com/blog/2005/07/27/hotdeploy-into-liferay350/</link>
		<comments>http://www.digizenstudio.com/blog/2005/07/27/hotdeploy-into-liferay350/#comments</comments>
		<pubDate>Wed, 27 Jul 2005 22:38:06 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/?p=65</guid>
		<description><![CDATA[I finally got around to try hot-deploying a standard JSR 168 portlet into Liferay Pro 3.5+Tomcat 5.5.9.  The portlet application being used is the Spring Portlet Support Sample Application.  The bottom line: it does the job, and in a satisfactory manner, meanwhile, it also leaves me some wishlist items.  
There is some [...]]]></description>
			<content:encoded><![CDATA[<p>I finally got around to try hot-deploying a standard JSR 168 portlet into Liferay Pro 3.5+Tomcat 5.5.9.  The portlet application being used is the <a href="http://opensource.atlassian.com/confluence/spring/display/JSR168/Home" rel="_blank">Spring Portlet Support Sample Application</a>.  The bottom line: it does the job, and in a satisfactory manner, meanwhile, it also leaves me some wishlist items.  <span id="more-65"></span></p>
<p>There is some <a href="http://www.liferay.com/web/guest/documentation/development/hot_deploy" rel="_blank">Liferay documentation</a> discussing how to hot deploy portlets.  Unfortunately it's mostly geared towards an Enterprise installation, whereas I'm working with the Professional. I end up with a heavily modified version of the deployer ant script provided in the document:</p>
<div class="igBar"><span id="lxml-25"><a href="#" onclick="javascript:showPlainTxt('xml-25'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-25">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;project</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"portlet-deployer"</span> <span style="color: #000066;">basedir</span>=<span style="color: #ff0000;">"."</span> <span style="color: #000066;">default</span>=<span style="color: #ff0000;">"deploy"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"init"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">environment</span>=<span style="color: #ff0000;">"env"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Tomcat --&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"app.server.type"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"tomcat"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"app.server.dir"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"E:\tomcats\5.5.9-liferay"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"app.server.deploy.dir"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"${app.server.dir}/webapps"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"liferay.dir"</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"${app.server.dir}/liferay"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;path</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"project.classpath"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;pathelement</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">"${env.ANT_HOME}/lib/ant.jar"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;fileset</span> <span style="color: #000066;">dir</span>=<span style="color: #ff0000;">"${app.server.dir}/shared/lib"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;pathelement</span> <span style="color: #000066;">location</span>=<span style="color: #ff0000;">"${app.server.dir}/common/lib/servlet-api.jar"</span> <span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/path<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/target<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;target</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"deploy"</span> <span style="color: #000066;">depends</span>=<span style="color: #ff0000;">"init"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;java</span> <span style="color: #000066;">classname</span>=<span style="color: #ff0000;">"com.liferay.portal.tools.PortletDeployer"</span> <span style="color: #000066;">classpathref</span>=<span style="color: #ff0000;">"project.classpath"</span> <span style="color: #000066;">fork</span>=<span style="color: #ff0000;">"true"</span> <span style="color: #000066;">newenvironment</span>=<span style="color: #ff0000;">"true"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Required Arguments --&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;jvmarg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"-Ddeployer.base.dir=./"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;jvmarg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"-Ddeployer.dest.dir=${app.server.deploy.dir}"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;jvmarg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"-Ddeployer.app.server.type=${app.server.type}"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;jvmarg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"-Ddeployer.portlet.taglib.dtd=${liferay.dir}/WEB-INF/tld/liferay-portlet.tld"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Optional Arguments --&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;jvmarg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"-Ddeployer.jboss.prefix=1"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;jvmarg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"-Ddeployer.tomcat.lib.dir=${app.server.dir}/shared/lib"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- Dependent Libraries --&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"${app.server.dir}/shared/lib/util-taglib.jar"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;arg</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">"${app.server.dir}/shared/lib/util-java.jar"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!--</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &lt;arg value=&quot;${app.server.deploy.dir}/ext.ear/lib/util-jsf.jar&quot; /&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; --&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/java<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/target<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/project<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
Once that and the Spring Portlet sample war are both ready in the 'my_portlets' directory, next thing you want to do is to copy everything under liferay/WEB-INF/lib into Tomcat's shared/lib.  That's for Liferay to be able to load the portlet applications.</p>
<p>Now just run "ant deploy" to do the actual deployment.  If Tomcat is running, and this is not the first time the same application is deployed, the deployer will spit out a bunch of warnings about "unable to delete" files.  They can actually be safely ignored.  The updated version of those files are actually in deployment by now if you go to check the timestamps.  And Tomcat will pick up the changes and reload the application in the next scanner run.  So, there, hot-<strong>re</strong>deploy works, too. <img src='http://www.digizenstudio.com/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Once deployed, the JSR 168 portlets are treated no differently from Liferay's built-in ones. You can add them right away from the dropdown list at the bottom of the page. The Spring portlet sample consists of four simple portlets which all seem to live happily. I just used the generic sample application without any container flavors. The only change I made was to copy the liferay/WEB-INF/tld/liferay-portlet.tld to the sample app's WEB-INF/tags directory, and rename it to 'portlet.tld'. However later on I took a look into the deployed application and found out that the Liferay deployer actually did something similar automatically while it processed the war file, so I suspect even that bit of modification wasn't necessary.</p>
<p>I also noticed another trick the deployer played with the war file - if there is a jar file in the war file that's already in shared/lib (e.g. log4j.jar), the deployer would automatically drop it from the application being deployed.  Assuming I didn't misunderstand this behavior, I seriously think it should at least be made optional by the deployer, because it could cause things anywhere from inconsistent to downright bad.  For example, Spring distributes in two ways - one way is a monolithic spring.jar, the other a set of spring-*.jar files grouping classes into different functionalities.  Liferay has a spring.jar, whereas the Spring sample application chooses to use a subset of spring-*.jar.  You get some inconsistencies right there if they are running different versions of Spring.  And what appeared to be "downright bad" to me is, since the web app specific log4j.jar is dropped, all the log4j configuration happening within the web app is now applied globally, and whichever portlet application that gets loaded the last takes over the control of the entire server's logging operation... <strong>Edit:</strong> I have since found out that if you point the property deployer.tomcat.lib.dir to somewhere else (say an empty directory), the jars wouldn't get filtered.</p>
<p>The last item on my wish list for the next Liferay release would be some more elegant way to hot-deploy portlets that doesn't involve any Ant script or command line execution. E.g., a directory scanner? or an Administrative portlet that lets me upload war files?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2005/07/27/hotdeploy-into-liferay350/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Composite Property Binding</title>
		<link>http://www.digizenstudio.com/blog/2005/06/22/composite-property-binding/</link>
		<comments>http://www.digizenstudio.com/blog/2005/06/22/composite-property-binding/#comments</comments>
		<pubDate>Wed, 22 Jun 2005 19:55:54 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/2005/06/22/composite-property-binding/</guid>
		<description><![CDATA[Very useful technique. See this forum post.
]]></description>
			<content:encoded><![CDATA[<p>Very useful technique. See <a href="http://forum.springframework.org/viewtopic.php?t=2424" rel="_blank">this forum post</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2005/06/22/composite-property-binding/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Inject Into Domain Objects</title>
		<link>http://www.digizenstudio.com/blog/2005/06/07/inject-into-domain-objects/</link>
		<comments>http://www.digizenstudio.com/blog/2005/06/07/inject-into-domain-objects/#comments</comments>
		<pubDate>Wed, 08 Jun 2005 02:08:23 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[aop]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/?p=54</guid>
		<description><![CDATA[There is an ongoing discussion on the Spring forums around DAO Reference Inside an Entity Domain Object?. Putting  aside the debate on whether the idea is sensible from a design perspective, a practical issue in implementing this approach is that, in a sophisticated application, domain objects, unlike those stateless business service objects or DAOs, [...]]]></description>
			<content:encoded><![CDATA[<p>There is an ongoing discussion on the Spring forums around <a href="http://forum.springframework.org/viewtopic.php?t=5918" rel="_blank">DAO Reference Inside an Entity Domain Object?</a>. Putting  aside the debate on whether the idea is sensible from a design perspective, a practical issue in implementing this approach is that, in a sophisticated application, domain objects, unlike those stateless business service objects or DAOs, are usually instantiated by the data access layer, e.g., an ORM tool such as Hibernate.  Therefore it's usually hard to inject dependencies into these domain objects through Spring.  In <a href="http://forum.springframework.org/viewtopic.php?t=301" rel="_blank">this forum post</a>, Rod Johnson and other guys described a way to inject into domain objects by handling Hibernate object lifecycle events, but as of Spring 1.2, the actually implementation is still in the Sandbox.  In this blog entry, I will describe another AOP-based approach that "virtually" injects a DAO reference (or any other Spring bean in general) into a domain object. <span id="more-54"></span></p>
<p>For the sake of discussion, let's say we have a domain object, <code>DomainObject</code>, and its DAO interface, <code>IDomainObjectDAO</code>.  The basic idea is actually very simple - we declare a method in DomainObject:</p>
<div class="igBar"><span id="ljava-30"><a href="#" onclick="javascript:showPlainTxt('java-30'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div id="java-30">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> DomainObject <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> IDomainObjectDAO getDomainObjectDAO<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=allinurl%3AUnsupportedOperationException+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">UnsupportedOperationException</span></a><span style="color: #66cc66;">&#40;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">"This method must be either AOP-intercepted, or overridden by a subclass, in order to provide a concrete implementation."</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
What we put in the method body does not matter, because the execution of this method will be intercepted with a Spring managed advice that actually gets the DAO instance from a Spring context and returns it on behalf of the method at runtime.</p>
<p>There can be many ways to implement the idea.  The one described below uses Aspectwerkz's offline weaving, and relies on the <a href="http://www.digizenstudio.com/blog/2005/06/06/global-references-to-applicationcontexts-unintrusively/">AppContextCollector</a>, and <a href="http://www.digizenstudio.com/blog/2005/06/06/spring-manage-aspectwerkz-aspects/">Spring-manage Aspectwerkz Aspects</a> ideas, so it might be beneficial to read those two blog entries first.</p>
<p>First we need a holder bean class as the runtime bridge to the target DAO reference:</p>
<div class="igBar"><span id="ljava-31"><a href="#" onclick="javascript:showPlainTxt('java-31'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div id="java-31">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">package com.<span style="color: #006600;">digizen</span>.<span style="color: #006600;">commons</span>.<span style="color: #006600;">aop</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import org.springframework.beans.BeansException;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import org.springframework.context.ApplicationContext;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import org.springframework.context.ApplicationContextAware;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> BeanReferenceAdvice <span style="color: #000000; font-weight: bold;">implements</span> ApplicationContextAware <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ApplicationContext contextRef_;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> beanName_;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setApplicationContext<span style="color: #66cc66;">&#40;</span>ApplicationContext context<span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> BeansException <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; contextRef_ = context;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> getBeanName<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> beanName_;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setBeanName<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> beanName<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; beanName_ = beanName;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Object</span></a> getBean<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> contextRef_.<span style="color: #006600;">getBean</span><span style="color: #66cc66;">&#40;</span>beanName_<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
The context definition file (with only the relevant parts):</p>
<div class="igBar"><span id="lxml-32"><a href="#" onclick="javascript:showPlainTxt('xml-32'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-32">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;</span>?xml <span style="color: #000066;">version</span>=<span style="color: #ff0000;">"1.0"</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">"UTF-8"</span>?<span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #00bbdd;">&lt;!DOCTYPE beans PUBLIC &quot;-//SPRING//DTD BEAN//EN&quot; &quot;http://www.springframework.org/dtd/spring-beans.dtd&quot;&gt;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;beans<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"domainObjectDAO"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"com.digizen.dao.DomainObjectDAOHibernateImpl"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"sessionFactory"</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;ref</span> <span style="color: #000066;">local</span>=<span style="color: #ff0000;">"mySessionFactory"</span><span style="font-weight: bold; color: black;">/&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- this declares the context collector instance.&nbsp; Note the contextKey, which will be referenced in the aop.xml below. --&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"contextCollector"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"com.digizen.commons.spring.AppContextCollector"</span> <span style="color: #000066;">singleton</span>=<span style="color: #ff0000;">"true"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"contextKey"</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;value<span style="font-weight: bold; color: black;">&gt;</span></span></span>appContext<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/value<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="color: #808080; font-style: italic;">&lt;!-- configure the advice bean.&nbsp; The beanName references the dao bean declared above.</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; We don't use the bean reference itself because we don't want this advice to hold on to any bean references.</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #808080; font-style: italic;">&nbsp; &nbsp;--&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"domainObjectDAORef"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"com.digizen.commons.aop.BeanReferenceAdvice"</span> <span style="color: #000066;">singleton</span>=<span style="color: #ff0000;">"true"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"beanName"</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;value<span style="font-weight: bold; color: black;">&gt;</span></span></span>domainObjectDAO<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/value<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/beans<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
Now in the aop.xml, just add:</p>
<div class="igBar"><span id="lxml-33"><a href="#" onclick="javascript:showPlainTxt('xml-33'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-33">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;aspect</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"appContext:domainObjectDAORef"</span> <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"com.digizen.commons.aop.BeanReferenceAdvice"</span> <span style="color: #000066;">container</span>=<span style="color: #ff0000;">"com.digizen.commons.aop.SpringBeanAspectContainer"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;pointcut</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"getDomainObjectDAOPC"</span><span style="font-weight: bold; color: black;">&gt;</span></span>execution(* com.digizen.domain.DomainObject.getDomainObjectDAO())<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/pointcut<span style="font-weight: bold; color: black;">&gt;</span></span></span>&gt;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;advice</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"getBean"</span> <span style="color: #000066;">type</span>=<span style="color: #ff0000;">"around"</span> <span style="color: #000066;">bind-to</span>=<span style="color: #ff0000;">"getDomainObjectDAOPC"</span><span style="font-weight: bold; color: black;">/&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/aspect<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
Once this is weaved into the DomainObject class, getDomainObjectDAO will be intercepted at runtime and will retrieve the DAO bean instance dynamically.  Because it does not cache the bean reference, this implementation is not limited to inject singleton beans, but also prototypes.</p>
<p>On first sight, this approach may cause some concerns in the readability of the codebase.  However as long as this is used consistently across the application, and becomes a pattern, it is not hard to realize the getter method is being injected - not harder than any average AOP intercepted code anyway.  Another plus of it is it does not rely on any specific ORM tool feature (such as the Hibernate events).  Finally, if a different way of providing the DAO is needed in the future, a subclass can always override this method.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2005/06/07/inject-into-domain-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring-manage Aspectwerkz Aspects</title>
		<link>http://www.digizenstudio.com/blog/2005/06/06/spring-manage-aspectwerkz-aspects/</link>
		<comments>http://www.digizenstudio.com/blog/2005/06/06/spring-manage-aspectwerkz-aspects/#comments</comments>
		<pubDate>Tue, 07 Jun 2005 02:23:33 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[aop]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/?p=53</guid>
		<description><![CDATA[Jonas BonÃ©r devised a clever way to spring-manage aspects in his blog  Spring and AspectWerkz - A Happy Marriage.  The only drawback in his approach is that the bean factory managing the aspects must be called a certain name, and be created by the SpringAspectContainer, which limits the usability because in many cases [...]]]></description>
			<content:encoded><![CDATA[<p>Jonas BonÃ©r devised a clever way to spring-manage aspects in his blog <a href="http://blogs.codehaus.org/people/jboner/archives/000826_spring_and_aspectwerkz_a_happy_marriage.html" rel="_blank"> Spring and AspectWerkz - A Happy Marriage</a>.  The only drawback in his approach is that the bean factory managing the aspects must be called a certain name, and be created by the <code>SpringAspectContainer</code>, which limits the usability because in many cases (e.g. in a Spring MVC powered Web application) contexts might have to be instantiated somewhere else.  So as the first application of the <code>AppContextCollector</code> I described in <a href="http://www.digizenstudio.com/blog/2005/06/06/global-references-to-applicationcontexts-unintrusively/">Global References To ApplicationContext(s) Unintrusively</a>, <code>SpringBeanAspectContainer</code> provides an alternative, unintrusive way to manage aspects in Spring. <span id="more-53"></span></p>
<p>The main implementation class is the <code>SpringBeanAspectContainer</code>. (See <a href="http://www.digizenstudio.com/blog/2005/06/06/global-references-to-applicationcontexts-unintrusively/">here</a> for the source code of <code>AppContextCollector</code>)</p>
<div class="igBar"><span id="ljava-35"><a href="#" onclick="javascript:showPlainTxt('java-35'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div id="java-35">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">package com.<span style="color: #006600;">digizen</span>.<span style="color: #006600;">commons</span>.<span style="color: #006600;">aop</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import java.util.Iterator;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import org.apache.log4j.Logger;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import org.codehaus.aspectwerkz.AspectContext;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import org.codehaus.aspectwerkz.aspect.AbstractAspectContainer;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import org.springframework.context.ApplicationContext;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import com.digizen.commons.spring.AppContextCollector;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> SpringBeanAspectContainer <span style="color: #000000; font-weight: bold;">extends</span> AbstractAspectContainer <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Logger LOG = Logger.<span style="color: #006600;">getLogger</span><span style="color: #66cc66;">&#40;</span>SpringBeanAspectContainer.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> SpringBeanAspectContainer<span style="color: #66cc66;">&#40;</span>AspectContext aspectContext<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; super<span style="color: #66cc66;">&#40;</span>aspectContext<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; @Override</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">protected</span> <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Object</span></a> createAspect<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> aspectName = getContext<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getAspectDefinition</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getName</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #993333;">int</span> pos = aspectName.<span style="color: #006600;">indexOf</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">':'</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>pos&gt; <span style="color: #cc66cc;color:#800000;">0</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> contextKey = aspectName.<span style="color: #006600;">substring</span><span style="color: #66cc66;">&#40;</span><span style="color: #cc66cc;color:#800000;">0</span>, pos<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> beanName = aspectName.<span style="color: #006600;">substring</span><span style="color: #66cc66;">&#40;</span>pos + <span style="color: #cc66cc;color:#800000;">1</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>LOG.<span style="color: #006600;">isDebugEnabled</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOG.<span style="color: #006600;">debug</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"loading aspect bean ["</span> + beanName + <span style="color: #ff0000;">"] from Spring context ["</span> + contextKey + <span style="color: #ff0000;">"]"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> AppContextCollector.<span style="color: #006600;">getContext</span><span style="color: #66cc66;">&#40;</span>contextKey<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">getBean</span><span style="color: #66cc66;">&#40;</span>beanName<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>LOG.<span style="color: #006600;">isDebugEnabled</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOG.<span style="color: #006600;">debug</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"No context key specified, try every one registered with AppContextCollector with bean name ["</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; + aspectName + <span style="color: #ff0000;">"]"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #66cc66;">&#40;</span>Iterator&lt;applicationcontext&gt; iAppContext = AppContextCollector.<span style="color: #006600;">getContextIterator</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;iAppContext.<span style="color: #006600;">hasNext</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>; <span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ApplicationContext appContext = iAppContext.<span style="color: #006600;">next</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=allinurl%3AObject+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">Object</span></a> bean = appContext.<span style="color: #006600;">getBean</span><span style="color: #66cc66;">&#40;</span>aspectName<span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>bean != <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>LOG.<span style="color: #006600;">isDebugEnabled</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOG.<span style="color: #006600;">debug</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Found bean '"</span> + aspectName + <span style="color: #ff0000;">"'"</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> bean;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">null</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>When being called to create an aspect instance, this class parses the aspect name specified its aop.xml definition into a context key and a bean name (e.g. "mainContext:myDAO" is parsed to a Spring bean named "myDAO" defined in an application context keyed by "mainContext" in <code>AppContextCollector</code>), and then uses those to get a bean from a Spring context previously created anywhere else.  If the aspect name has only a bean name (i.e. doesn't have a ':' in the name string), the container searches through all the contexts in <code>AppContextCollector</code> until it finds a bean with that name.</p>
<p></applicationcontext></p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2005/06/06/spring-manage-aspectwerkz-aspects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Global References To ApplicationContext(s) Unintrusively</title>
		<link>http://www.digizenstudio.com/blog/2005/06/06/global-references-to-applicationcontexts-unintrusively/</link>
		<comments>http://www.digizenstudio.com/blog/2005/06/06/global-references-to-applicationcontexts-unintrusively/#comments</comments>
		<pubDate>Mon, 06 Jun 2005 23:58:19 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/?p=52</guid>
		<description><![CDATA[We all know singletons are evil, but sometimes you can't do without them...]]></description>
			<content:encoded><![CDATA[<p>Spring provides an out-of-box <code>SingletonBeanFactoryLocator</code> (or <code>WebApplicationContextUtils</code> in the case of a Web application) for code to globally reference bean factories and application contexts.  The class takes a resource string (by default "classpath*:beanRefFactory.xml") and builds a bean factory from all the definition files on the classpath matching the resource string.  Most of the time this suffices - straightforward and easy to use.  However this locator-also-creates approach can be inconvenient in some cases, where I don't find myself having control over when and how to create the bean factories.  This is where my "passive" AppContextCollector comes in. <span id="more-52"></span></p>
<p>The implementation itself is quite simple and straightforward.</p>
<div class="igBar"><span id="ljava-36"><a href="#" onclick="javascript:showPlainTxt('java-36'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div id="java-36">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">package com.<span style="color: #006600;">digizen</span>.<span style="color: #006600;">commons</span>.<span style="color: #006600;">spring</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import org.apache.log4j.Logger;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import java.lang.ref.WeakReference;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import java.util.HashMap;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import java.util.Iterator;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import java.util.Map;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import org.springframework.beans.BeansException;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import org.springframework.beans.factory.BeanInitializationException;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import org.springframework.beans.factory.InitializingBean;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import org.springframework.context.ApplicationContext;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import org.springframework.context.ApplicationContextAware;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import com.digizen.commons.util.ReferenceIteratorWrapper;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AppContextCollector <span style="color: #000000; font-weight: bold;">implements</span> ApplicationContextAware, InitializingBean <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">static</span> <span style="color: #000000; font-weight: bold;">final</span> Logger LOG = Logger.<span style="color: #006600;">getLogger</span><span style="color: #66cc66;">&#40;</span>AppContextCollector.<span style="color: #000000; font-weight: bold;">class</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #993333;">static</span> Map&lt;string , WeakReference&lt;ApplicationContext&gt;&gt; contextMap_ =</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">new</span> HashMap&lt;/string&gt;&lt;string , WeakReference&lt;ApplicationContext&gt;&gt;<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> currentKey_;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> ApplicationContext currentContext_;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">static</span> ApplicationContext getContext<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> key<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> contextMap_.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span>key<span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">static</span> Iterator&lt;applicationcontext&gt; getContextIterator<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">new</span> ReferenceIteratorWrapper&lt;/applicationcontext&gt;&lt;applicationcontext&gt;<span style="color: #66cc66;">&#40;</span>contextMap_.<span style="color: #006600;">values</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">iterator</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setApplicationContext<span style="color: #66cc66;">&#40;</span>ApplicationContext applicationContext<span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> BeansException <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; currentContext_ = applicationContext;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> getContextKey<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> currentKey_;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> setContextKey<span style="color: #66cc66;">&#40;</span><a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&amp;bntl=1"><span style="color: #aaaadd; font-weight: bold;">String</span></a> contextKey<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; currentKey_ = contextKey;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> afterPropertiesSet<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #000000; font-weight: bold;">throws</span> BeanInitializationException<span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>currentKey_ == <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">throw</span> <span style="color: #000000; font-weight: bold;">new</span> BeanInitializationException<span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"Property 'contextKey' is required."</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; contextMap_.<span style="color: #006600;">put</span><span style="color: #66cc66;">&#40;</span>currentKey_, <span style="color: #000000; font-weight: bold;">new</span> WeakReference&lt;/applicationcontext&gt;&lt;applicationcontext&gt;<span style="color: #66cc66;">&#40;</span>currentContext_<span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>LOG.<span style="color: #006600;">isDebugEnabled</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; LOG.<span style="color: #006600;">debug</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"ApplicationContext '"</span> + currentKey_ + <span style="color: #ff0000;">"' is collected."</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; currentKey_ = <span style="color: #000000; font-weight: bold;">null</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; currentContext_ = <span style="color: #000000; font-weight: bold;">null</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>To collect an <code>ApplicationContext</code> and make it available globally through a key, declare a Spring bean in the definition file for that particular <code>ApplicationContext</code>:</p>
<div class="igBar"><span id="lxml-37"><a href="#" onclick="javascript:showPlainTxt('xml-37'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">XML:</span>
<div id="xml-37">
<div class="xml">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;bean</span> <span style="color: #000066;">id</span>=<span style="color: #ff0000;">"contextCollector"</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #000066;">class</span>=<span style="color: #ff0000;">"com.digizen.commons.spring.AppContextCollector"</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; <span style="color: #000066;">singleton</span>=<span style="color: #ff0000;">"true"</span><span style="font-weight: bold; color: black;">&gt;</span></span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">"contextKey"</span><span style="font-weight: bold; color: black;">&gt;</span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;value<span style="font-weight: bold; color: black;">&gt;</span></span></span>mainContext<span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/value<span style="font-weight: bold; color: black;">&gt;</span></span></span><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/property<span style="font-weight: bold; color: black;">&gt;</span></span></span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #009900;"><span style="font-weight: bold; color: black;">&lt;/bean<span style="font-weight: bold; color: black;">&gt;</span></span></span> </div>
</li>
</ol>
</div>
</div>
</div>
<p>
Anywhere in your code, you can then use:</p>
<div class="igBar"><span id="ljava-38"><a href="#" onclick="javascript:showPlainTxt('java-38'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">JAVA:</span>
<div id="java-38">
<div class="java">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">AppContextCollector.<span style="color: #006600;">getContext</span><span style="color: #66cc66;">&#40;</span><span style="color: #ff0000;">"mainContext"</span><span style="color: #66cc66;">&#41;</span>;<span style="color: #66cc66;">&#91;</span>/code<span style="color: #66cc66;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">To get the reference to the context instance.</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #006600;">Appendix</span>: The &lt;code&gt;ReferenceIteratorWrapper&lt;/code&gt; <span style="color: #000000; font-weight: bold;">class</span><span style="color: #66cc66;">&#40;</span>referenced in the above <span style="color: #000000; font-weight: bold;">class</span><span style="color: #66cc66;">&#41;</span> to avoid hanging onto any context references as they are supposed to be kept in weak references:</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#91;</span>code lang=<span style="color: #ff0000;">"java"</span><span style="color: #66cc66;">&#93;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">package com.<span style="color: #006600;">digizen</span>.<span style="color: #006600;">commons</span>.<span style="color: #006600;">util</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import java.lang.ref.Reference;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #a1a100;">import java.util.Iterator;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">final</span> <span style="color: #000000; font-weight: bold;">class</span> ReferenceIteratorWrapper&lt;t&gt; <span style="color: #000000; font-weight: bold;">implements</span> Iterator&lt;/t&gt;&lt;t&gt; <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">private</span> Iterator&lt;? <span style="color: #000000; font-weight: bold;">extends</span> Reference&lt;T&gt;&gt; iterator_;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> ReferenceIteratorWrapper<span style="color: #66cc66;">&#40;</span>Iterator&lt;? <span style="color: #000000; font-weight: bold;">extends</span> Reference&lt;T&gt;&gt; iterator<span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; iterator_ = iterator;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">boolean</span> hasNext<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> iterator_.<span style="color: #006600;">hasNext</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> T next<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> iterator_.<span style="color: #006600;">next</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> T nextNotNull<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #66cc66;">&#40;</span>iterator_.<span style="color: #006600;">hasNext</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; T t = iterator_.<span style="color: #006600;">next</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>.<span style="color: #006600;">get</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #66cc66;">&#40;</span>t != <span style="color: #000000; font-weight: bold;">null</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> t;</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000000; font-weight: bold;">null</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #993333;">void</span> remove<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; iterator_.<span style="color: #006600;">remove</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span></div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #66cc66;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></t></applicationcontext></string></p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2005/06/06/global-references-to-applicationcontexts-unintrusively/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>RedirectView Fails In IE</title>
		<link>http://www.digizenstudio.com/blog/2005/05/21/redirectview-fails-in-ie/</link>
		<comments>http://www.digizenstudio.com/blog/2005/05/21/redirectview-fails-in-ie/#comments</comments>
		<pubDate>Sat, 21 May 2005 06:04:39 +0000</pubDate>
		<dc:creator>Jing Xue</dc:creator>
				<category><![CDATA[microsoft]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://www.digizenstudio.com/blog/2005/05/21/redirectview-fails-in-ie/</guid>
		<description><![CDATA[This isn't really a Spring issue, but the symptom was reported on the Spring Forum.  It's good to know that IE has this limitation of 2083 characters for query strings.
]]></description>
			<content:encoded><![CDATA[<p>This isn't really a Spring issue, but the symptom was <a href="http://forum.springframework.org/viewtopic.php?t=5532" rel="_blank">reported on the Spring Forum</a>.  It's good to know that IE has this limitation of 2083 characters for query strings.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.digizenstudio.com/blog/2005/05/21/redirectview-fails-in-ie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

