<?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>Sun, 06 May 2012 19:47:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Using Struts 2&#8242;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>sonnygill</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 MyServiceImpl.java &#8230; <a href="http://sonnygill.net/java/struts2-dependency-injection/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></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; title: ; notranslate">
...
 &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; title: ; notranslate">
...
 @Inject(&quot;myVal&quot;)
 public void setMyVal(String myVal) {
 this.myVal = Integer.parseInt(myVal);
 }
...
</pre>
<p>MyAction.java</p>
<pre class="brush: java; title: ; notranslate">
...
 @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>

