<?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>Juggling Eggs &#187; Struts</title>
	<atom:link href="http://sonnygill.net/tag/struts/feed/" rel="self" type="application/rss+xml" />
	<link>http://sonnygill.net</link>
	<description>Priceless eggs, variable gravity</description>
	<lastBuildDate>Tue, 15 Feb 2011 10:54:51 +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>Using Struts 2&#8217;s native dependency injection support</title>
		<link>http://sonnygill.net/java/struts2-dependency-injection/</link>
		<comments>http://sonnygill.net/java/struts2-dependency-injection/#comments</comments>
		<pubDate>Thu, 12 Feb 2009 13:35:23 +0000</pubDate>
		<dc:creator>Sonny Gill</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Struts]]></category>

		<guid isPermaLink="false">http://sonnygill.wordpress.com/?p=88</guid>
		<description><![CDATA[Since I knew that Struts 2 used Guice internally, I was curious if the native DI support in S2 could be used in a simple application. A little bit of digging and fiddling around showed what is possible.
struts.xml

...
 &#60;constant name=&#34;myVal&#34; value=&#34;9&#34; /&#62;
 &#60;bean name=&#34;myService&#34; type=&#34;prac.MyService&#34; class=&#34;prac.MyServiceImpl&#34; /&#62;
...

MyServiceImpl.java

...
 @Inject(&#34;myVal&#34;)
 public void setMyVal(String myVal) {
 this.myVal = [...]]]></description>
			<content:encoded><![CDATA[<p>Since I knew that Struts 2 used Guice internally, I was curious if the native DI support in S2 could be used in a simple application. A little bit of digging and fiddling around showed what is possible.</p>
<p>struts.xml</p>
<pre class="brush: xml;">
...
 &lt;constant name=&quot;myVal&quot; value=&quot;9&quot; /&gt;
 &lt;bean name=&quot;myService&quot; type=&quot;prac.MyService&quot; class=&quot;prac.MyServiceImpl&quot; /&gt;
...
</pre>
<p>MyServiceImpl.java</p>
<pre class="brush: java;">
...
 @Inject(&quot;myVal&quot;)
 public void setMyVal(String myVal) {
 this.myVal = Integer.parseInt(myVal);
 }
...
</pre>
<p>MyAction.java</p>
<pre class="brush: java;">
...
 @Inject(&quot;myService&quot;)
 public void setMyService(MyService myService) {
 this.myService = myService;
 }
...
</pre>
<p>This will create a single instance of MyService with myVal injected into it.<br />
And on every invocation of MyAction, that MyService instance will be injected into it.<br />
Sweet!</p>
<p>Of course, this is part of Struts internals, so these can change at any time. It is probably not a good idea to use it on a real world system.</p>
]]></content:encoded>
			<wfw:commentRss>http://sonnygill.net/java/struts2-dependency-injection/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

